2017-06-02 82 views
1

我是Python新手,希望Stackoverflow社區能夠幫助我解決我遇到的問題。我有以下代碼,當我嘗試運行該程序時,選項菜單(下拉菜單)不會出現。只有一個空的窗口出現。我怎樣才能解決這個問題?Tkinter選項菜單不顯示

# Python 3.6 
from tkinter import * 

root = Tk() 

class Application(Frame): 
    def __init__(self): 
     Frame.__init__(self) 
     self.create_vars() 
     self.create_widgets() 

    def create_vars(self): 
     self.tee_strvar = StringVar() 
     self.tee_strvar.set("Select tee") 

    def create_widgets(self): 
     self.tee_dropdown = OptionMenu(self, self.tee_strvar, "yellow", "red") 
     self.tee_dropdown.grid(row=1, column=1) 

    def check_tee(self): 
     pass 


app = Application() 

root.mainloop() 

非常感謝你的幫助,請回答初學者友好如果可能的話:)

回答

1

你沒包/格/放置應用程序...你沒在通過主任,所以默認情況下它使用根窗口作爲主窗口,但「應用程序」即 - 一個框架對象不由幾何管理器管理。

+0

非常感謝,app.grid()爲我工作! –