I'm currently trying to create a Python3 Tkinter program which I can launch by double clicking or opening from other python scripts, instead of going through idle.
我目前正在尝试创建一个Python3 Tkinter程序,我可以通过双击或从其他python脚本打开来启动它,而不是通过idle。
So far I've had little luck, as when I attempt to launch the script the console opens for a moment and then crashes.
到目前为止,我的运气并不好,因为当我尝试启动脚本时,控制台会打开一会儿,然后崩溃。
EDIT: Removing the logo segment of code allows the program to run. Any ideas why and how to fix it? Also I have not had to run a program via the console before so little luck there.
编辑:删除代码段代码允许程序运行。有什么想法和方法吗?我也没有必要通过控制台运行一个程序,所以在那里没有多少运气。
from tkinter import *
from tkinter import ttk
root = Tk()
root.title("Kinematics")
Logo_frame = LabelFrame(root, bg = "white")
Logo_frame.grid(row=0, column=12, sticky = "NSEW")
#Logo
Logo = Image(file="Logo-S.gif")
image_label = ttk.Label(Logo_frame, image=Logo)
image_label.grid(row=0, column=0, rowspan = 3)
root.mainloop()
2 个解决方案
#1
0
The error from your present code is:
您当前代码的错误是:
Exception ignored in: <bound method Image.__del__ of <tkinter.Image object at 0x7f1aa91df2e8>>
Traceback (most recent call last):
File "/usr/lib/python3.5/tkinter/__init__.py", line 3357, in __del__
if self.name:
AttributeError: 'Image' object has no attribute 'name'
Traceback (most recent call last):
File "/home/sunbear/Coding/python35/tkinter/*_questions/test52.py", line 22, in <module>
Logo = Image(file="Logo-S.gif")
TypeError: __init__() missing 1 required positional argument: 'imgtype'
There is a typo in your command in line 22(your original code before edit). You need the following correction to overcome this error, i.e.:
在第22行(编辑之前的原始代码)中有一个输入错误。为了克服这个错误,你需要下面的纠正,即:
#Logo
#Logo = Image(file="Logo-S.gif")
Logo = PhotoImage(file="Logo-S.gif") #you should change to this.
You can read more about when to use PhotoImage and Image using this link I gave you.
你可以阅读更多关于何时使用我给你的这个链接使用图片和图片。
#2
#1
0
The error from your present code is:
您当前代码的错误是:
Exception ignored in: <bound method Image.__del__ of <tkinter.Image object at 0x7f1aa91df2e8>>
Traceback (most recent call last):
File "/usr/lib/python3.5/tkinter/__init__.py", line 3357, in __del__
if self.name:
AttributeError: 'Image' object has no attribute 'name'
Traceback (most recent call last):
File "/home/sunbear/Coding/python35/tkinter/*_questions/test52.py", line 22, in <module>
Logo = Image(file="Logo-S.gif")
TypeError: __init__() missing 1 required positional argument: 'imgtype'
There is a typo in your command in line 22(your original code before edit). You need the following correction to overcome this error, i.e.:
在第22行(编辑之前的原始代码)中有一个输入错误。为了克服这个错误,你需要下面的纠正,即:
#Logo
#Logo = Image(file="Logo-S.gif")
Logo = PhotoImage(file="Logo-S.gif") #you should change to this.
You can read more about when to use PhotoImage and Image using this link I gave you.
你可以阅读更多关于何时使用我给你的这个链接使用图片和图片。