[問題] tkinter的label跑不出來

看板Python作者 (8888C885)時間5年前 (2019/06/02 17:32), 編輯推噓2(206)
留言8則, 4人參與, 5年前最新討論串1/1
各位高手,小弟最近自學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

06/02 18:16, 5年前 , 1F
沒在用TK,不過我猜你是因為把label放在mainloop後面的關係
06/02 18:16, 1F

06/02 18:39, 5年前 , 2F
感謝大大!解決了~~另外想請問您是否推薦用pyqt學
06/02 18:39, 2F

06/02 18:39, 5年前 , 3F
習gui呢
06/02 18:39, 3F

06/02 21:12, 5年前 , 4F
PyQT我個人是比較推,因為可以做的事比較多,但真的比較難
06/02 21:12, 4F

06/02 21:12, 5年前 , 5F
06/02 21:12, 5F

06/04 08:57, 5年前 , 6F
mainloop這個函式要放在最下面
06/04 08:57, 6F

06/07 00:24, 5年前 , 7F
我的工作就是在寫QT,能做的事真的很多,但各種漏
06/07 00:24, 7F

06/07 00:24, 5年前 , 8F
記憶體...
06/07 00:24, 8F
文章代碼(AID): #1SyvUY72 (Python)