我需要将我的代码(在Python IDE中编写的Python 2.7)放到我的论文的word文档中,但我很难找到一种方法来复制它并保持格式化,我尝试粘贴特殊而且没有运气.到目前为止,我发现的唯一方法是截图,但只有超过1000行代码,这是非常费力的.
我正在尝试使用下面的代码创建一个按钮并更改高度和宽度,但实际按钮不会在物理上显示.但是,如果您将鼠标悬停在它应该是的区域上并单击它将打开新窗口.有任何想法吗?
import sys
from tkinter import *
#main menu
def mmWindow():
mmWindow=Tk()
mmWindow.geometry('600x600')
#first window
mWindow= Tk()
mWindow.geometry('1920x1080+0+0')
mWindow.title('DMX512 Controller')
wtitle = Label (mWindow, text = "Pi DMX", fg = 'blue')
wtitle.place(x = 640, y = 100)
#main menu button
mmbutton = Button (mWindow, text = "Main Menu",command = mmWindow)
mmbutton.place( x=200, y = 200)
mmbutton.config(width=200, height=200)
Run Code Online (Sandbox Code Playgroud) 嗨,我正尝试将图像作为背景放在我的一个按钮上,我已经在主窗口中的许多其他按钮上完成了此操作,但是此特定按钮位于顶层窗口内,图像不会像这样加载应该,有人知道为什么吗?(我也尝试过定义按钮的宽度和高度,但这仍然不显示图像)
def rec_window():
recw = Toplevel(width=500,height=500)
recw.title('Record To.....')
img1 = PhotoImage(file="C:/Users/Josh Bailey/Desktop/pi_dmx/Gif/mainmenu.gif")
Button(recw, image=img1, command=rec_preset_1).grid(row=1, column=1)
Button(recw, text="Preset 2", bg = 'grey70',width=40, height=12,command=rec_preset_2).grid(row=1, column=2)
Button(recw, text="Preset 3", bg = 'grey70',width=40, height=12,command=rec_preset_3).grid(row=2, column=1)
Button(recw, text="Preset 4", bg = 'grey70',width=40, height=12,command=rec_preset_4).grid(row=2, column=2)
Button(recw, text="Cancel", bg='grey70', width=20, height=6, command=recw.destroy). grid(row=3,column=1,columnspan=2, pady=30)
Run Code Online (Sandbox Code Playgroud)