Tk窗口没有显示任何内容

时间:2014-11-01 14:45:56

标签: python python-3.x tkinter

我正在使用tkinter模块在python 3.4.2中制作游戏,但由于某种原因,Tk窗口出现但我的按钮或标签都没有显示出来。任何想法?
这是我的代码。

 root = Tk()
 frameone = Frame(root, width = 400, height = 400)

 lone = Label(frameone, text = 'NumberGuessingGame. Author: ************. Version: 6.0', fg = 'red')
 lone.grid(row = 0)

 ltwo = Label(frameone, text = 'This is a game in which you select your difficulty.', fg = 'red')
 ltwo.grid(row = 1)

 lthree = Label(frameone, text = 'Then the computer generates a number which you have to guess.', fg = 'red')
 lthree.grid(row = 2)

 lfour = Label(frameone, text = 'The computer then gives you a score', fg = 'red')
 lfour.grid(row = 3)

 buttonone = Button(frameone, text = 'Continue')
 buttonone.grid(row = 0, column = 1)

 root.mainloop()  

我确实有代码,只是因为这很重要。

1 个答案:

答案 0 :(得分:3)

如果未布置包含小部件,则不会显示子小部件。

packgridplace框架小部件:

root = Tk()
frameone = Frame(root, width=400, height=400)
frameone.grid(row=0, column=0)  # <----
...