作者aegisaaakhkh (8888C885)
看板Python
标题[问题] tkinter的label跑不出来
时间Sun Jun 2 17:32:16 2019
各位高手,小弟最近自学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://webptt.com/cn.aspx?n=bbs/Python/M.1559467938.A.1C2.html
1F:→ froce: 没在用TK,不过我猜你是因为把label放在mainloop後面的关系 06/02 18:16
2F:→ aegisaaakhkh: 感谢大大!解决了~~另外想请问您是否推荐用pyqt学 06/02 18:39
3F:→ aegisaaakhkh: 习gui呢 06/02 18:39
4F:推 froce: PyQT我个人是比较推,因为可以做的事比较多,但真的比较难 06/02 21:12
5F:→ froce: 学 06/02 21:12
6F:推 bugbug777: mainloop这个函式要放在最下面 06/04 08:57
7F:→ zo6596001: 我的工作就是在写QT,能做的事真的很多,但各种漏 06/07 00:24
8F:→ zo6596001: 记忆体... 06/07 00:24