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