[问题] tkinter的label跑不出来

楼主: aegisaaakhkh (a9293340)   2019-06-02 17:32:16
各位高手,小弟最近自学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发生什么问题了吗....?
要怎么解决
作者: froce (froce)   2019-06-02 18:16:00
没在用TK,不过我猜你是因为把label放在mainloop后面的关系
楼主: aegisaaakhkh (a9293340)   2019-06-02 18:39:00
感谢大大!解决了~~另外想请问您是否推荐用pyqt学习gui呢
作者: froce (froce)   2019-06-02 21:12:00
PyQT我个人是比较推,因为可以做的事比较多,但真的比较难学
作者: bugbug777 (sil)   2019-06-04 08:57:00
mainloop这个函式要放在最下面
作者: zo6596001 (超帅肥宅)   2019-06-07 00:24:00
我的工作就是在写QT,能做的事真的很多,但各种漏内存...

Links booklink

Contact Us: admin [ a t ] ucptt.com