看板 Python 關於我們 聯絡資訊
各位高手,小弟最近自學tkinter,在按照網上範例輸入code如下: import tkinter as tk window = tk.Tk() window.title('my window') window.geometry('200x100') window.mainloop() l = tk.Label(window, text='OMG! this is TK!', bg='green', font=('Arial', 12), width=15, height=2 ) l.pack() 執行時雖然有跑出視窗,但label並沒有顯示出來,關閉時出現下方問題: Traceback (most recent call last): File ".\tk1.py", line 13, in <module> width=15, height=2 File "C:\Users\f2101\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 2766, in __init__ Widget.__init__(self, master, 'label', cnf, kw) File "C:\Users\f2101\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 2299, in __init__ (widgetName, self._w) + extra + self._options(cnf)) _tkinter.TclError: can't invoke "label" command: application has been destroyed 想請教各位大神,我的tkinter發生甚麼問題了嗎....? 要怎麼解決 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.16.134 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1559467938.A.1C2.html
froce: 沒在用TK,不過我猜你是因為把label放在mainloop後面的關係 06/02 18:16
aegisaaakhkh: 感謝大大!解決了~~另外想請問您是否推薦用pyqt學 06/02 18:39
aegisaaakhkh: 習gui呢 06/02 18:39
froce: PyQT我個人是比較推,因為可以做的事比較多,但真的比較難 06/02 21:12
froce: 學 06/02 21:12
bugbug777: mainloop這個函式要放在最下面 06/04 08:57
zo6596001: 我的工作就是在寫QT,能做的事真的很多,但各種漏 06/07 00:24
zo6596001: 記憶體... 06/07 00:24