1
我在python 3.4.2中用tkinter模塊製作遊戲,但由於某些原因Tk窗口出現了,但我的按鈕或標籤都沒有出現。有任何想法嗎?
這是我的代碼。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,frameone,lone和lone.pack就足夠了。其他小部件只是噪音。隨着噪聲消除(或註釋掉),您可能更容易注意到frameone.pack丟失。 – 2014-11-01 20:05:13