【发布时间】:2019-05-01 12:57:00
【问题描述】:
(注意:带边框的按钮是背景的一部分) 我想将真正的按钮放在图像后面,这样我就好像在后台按下按钮,但是,我实际上是在按下它后面的按钮。
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
background_image = tk.PhotoImage(file="Mainmenu.png") # Displays whats in the file
background_label = tk.Label(self, image=background_image) # Makes tk.Label display the background_image
background_label.place(x=0, y=0, relwidth=1, relheight=1) # Adjusts the height/width
background_label.image = background_image # Recognises the label as an image
button1 = tk.Button(self, text="Play", bg="red", fg="black", height=2, width=15,
command=lambda: controller.show_frame("Play"))
button2 = tk.Button(self, text="Settings", bg="yellow", fg="black", height=2, width=15,
command=lambda: controller.show_frame("Settings"))
button3 = tk.Button(self, text="Quit", bg="white", fg="black", height=2, width=15, cursor="pirate",
command=exit)
button1.place(x="300",y="240")
button2.place(x="480",y="240")
button3.place(x="390",y="300")
button1.config(font=("System", 10))
button2.config(font=("System", 10))
button3.config(font=("System", 10))
【问题讨论】:
-
您无法按照标题中的要求进行操作。但是,您可以将图像添加到按钮本身,然后提供文本以覆盖它。
-
你为什么要按钮?为什么不让用户直接点击后台呢?
-
Bryan Oakley 如何做到这一点?
-
您可以将
"<Button-1>"绑定到根据鼠标位置执行不同命令的函数。
标签: python tkinter tkinter-canvas