Python 2.7 Tkinter 小部件未显示 [英] Python 2.7 Tkinter widgets not showing
本文介绍了Python 2.7 Tkinter 小部件未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在设置 Tkinter 应用程序,由于某种原因,基本小部件没有显示.我得到了一个空白的 Tkinter 窗口,没有别的.
I'm working on setting up a Tkinter app, for some reason, the basic widgets aren't showing. I'm getting a blank Tkinter window, and nothing else.
以下是我的代码.我试过添加简单的小部件,但没有用.
The following is my code. I've tried adding simple widgets, and that's not working.
这是我的代码:
import Tkinter as Tk
import ttk as ttk
class MainApplication(Tk.Frame):
def __init__(self, root):
Tk.Frame.__init__(self)
self.root = root
self.root.title('JRSuite')
root.attributes('-fullscreen', True)
self.mainWindow = Tk.Frame(self)
self.mainWindow.pack()
self._windowSetup()
def _windowSetup(self):
'''Sets up the basic components of the main window'''
self.tree = ttk.Treeview(self.mainWindow)
self.tree.pack()
self.note = ttk.Notebook(self.mainWindow)
self.note.pack()
self.tree.insert('', 'end', text = 'Woohoo')
if __name__ == '__main__':
root = Tk.Tk()
app = MainApplication(root)
app.mainloop()
推荐答案
你应该pack
应用程序:
if __name__ == '__main__':
root = Tk.Tk()
app = MainApplication(root)
app.pack()
app.mainloop()
这篇关于Python 2.7 Tkinter 小部件未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文