我正在通過在線教程學習如何使用Tkinter製作GUI。但是我在使用.grid()函數時遇到問題。當使用.grid時,Python Tkinter未打開()
這裏是我到目前爲止有:
from Tkinter import *
root = Tk()
title = Label(root, text = "Hello World")
title.pack()
name = Label(root, text = "Name")
password = Label(root, text = "Password")
entry_name = Entry(root)
entry_password = Entry(root)
name.grid (row = 0, sticky = E)
password.grid (row = 0, sticky = E)
entry_name.grid (row = 0, column = 1)
entry_password.grid (row = 1, column = 1)
check = Checkbutton(root, text = "Keep me logged in")
check.grid(columnspan = 2)
root.mainloop()
因此,有問題的IM是,只要我包括第一行:
name.grid(row = 0, sticky = E)
然後運行該腳本,有沒有錯誤,但沒有打開。該程序只是掛起,我必須關閉命令提示符才能重新獲得控制權。
如果我使用.grid()註釋掉所有行,它們的程序將正常工作,並會打開一個窗口,其中包含我的標題。
那麼,有沒有人知道我做錯了什麼? 即時通訊使用Python 2.7
看起來你已經在'root'內使用'pack()'了。混合幾何管理器通常會產生某種錯誤信息,但是您是否嘗試過修復? – TigerhawkT3
您不能使用包和網格 –