2016-03-08 92 views
0

我無法獲得mButton1以顯示一個菜單,顯示Orlando及其下方的Cancun。 我正在嘗試構建一個窗口小部件按鈕,點擊時它會在菜單中顯示2個城市,例如預訂航班時。使用tkinter無法看到python上的菜單按鈕

from tkinter import * 

class App: 
    def __init__(self, master): 

     frame = Frame(master) 
     frame.grid() 

     self.label1 = Label(frame, text = "Destination:") 
     self.label2 = Label(frame, text = "Adults:") 
     self.label3 = Label(frame, text = "Child:") 
     self.label1.grid(row=0) 
     self.label2.grid(row=1) 
     self.label3.grid(row=2) 

     self.entry2 = Entry(frame) 
     self.entry3 = Entry(frame) 
     self.entry2.grid(row=1,column = 1) 
     self.entry3.grid(row=2,column = 1) 

     self.button = Checkbutton(frame, text="Roundtrip:") 
     self.button.grid(row=3) 

     **self.mButton1 = Menubutton(frame, text = "Destinations", relief=RAISED) 
     self.mButton1.grid(row = 0, column = 1) 
     self.mButton1.menu = Menu(frame, tearoff = 0) 
     self.mButton1["menu"] =self.mButton1.menu 
     self.orlandoVar = IntVar() 
     self.cancunVar = IntVar() 
     self.mButton1.menu.add_checkbutton (label= "Orlando", variable = self.orlandoVar) 
     self.mButton1.menu.add_checkbutton (label = "Cancun", variable = self.cancunVar) 
     self.mButton1.grid** 

root = Tk() 
+0

「__init__」是在它自己的行縮進得當,(並且對每邊,你可能有兩個下劃線,但它顯示爲大膽,因爲它沒有格式化爲代碼)http://www.diveintopython.net/object_oriented_framework/defining_classes.html#d0e11720 –

回答

0

的菜單必須是菜單按鈕的子

self.mButton1.menu = Menu(self.mButton1, ...) 
+0

是的!我剛剛發現太過分了。儘管如此,非常感謝! –