2
我是新来的编程和python,所以我提前感谢您的耐心。python - TKinter - 我可以发送背景吗?
我创建了一个类,它为背景创建一个带有测试图像的新窗口(“test1.gif”)。
我还在同一个班级中创建了一个下拉菜单,让您在3个国家之间进行选择。
我可以评论使背景或使菜单和其他将显示的代码的代码。不过,我希望菜单出现在背景之上。当我运行完整的代码时,我只能看到背景。
我很欣赏我可能在这里丢失了一些非常明显的东西,如果有人能指出这是什么。
谢谢你的时间。 丹
from Tkinter import *
import Tkinter as tk
class dropDown():
def __init__(self, master):
#background set_up
image1 = tk.PhotoImage(file="test1.gif")
w = image1.width()
h = image1.height()
root.geometry("%dx%d+0+0" % (w, h))
panel1 = tk.Label(root, image=image1)
panel1.pack(side='top', fill='both', expand='yes')
# save the panel's image from 'garbage collection'
panel1.image = image1
#Drop down menu
self.var = StringVar(master)
self.var.set('Alaska') # initial value
#Have not used countries list just pasted
self.option = OptionMenu(master, self.var, 'Alberta', 'Australia')
self.option.pack()
root = Tk()
root.title('drop down test')
dropDown(root)
mainloop()
感谢mgilson,它会把我永远拿出来工作!我想我理解你的解决方案。我会看看我是否可以解决如何让框架继承你所建议的下拉菜单。再次感谢。 – hemmy
@ user1451238 - 我也在为此挠了挠头。 – mgilson
@ user1451238 - 我发布了一个框架子类化的例子。随意修改,只要你认为合适。 – mgilson