gpt4 book ai didi

python - Tk 窗口不显示任何内容

转载 作者:行者123 更新时间:2023-11-30 23:18:31 24 4
gpt4 key购买 nike

我正在使用 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()

在此之后我确实有代码,以防万一。

最佳答案

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

打包网格放置框架小部件:

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

关于python - Tk 窗口不显示任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26690365/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com