Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

求助,运行时tkinter报错 #1

Closed
WoodwindHu opened this issue Mar 20, 2023 · 6 comments
Closed

求助,运行时tkinter报错 #1

WoodwindHu opened this issue Mar 20, 2023 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@WoodwindHu
Copy link

❯ python3 ./EdgeGPT-GUI.py
DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. Please don't rely on it. Set TK_SILENCE_DEPRECATION=1 to suppress this warning.
Traceback (most recent call last):
  File "/Users/potapo/github/EdgeGPT-GUI/./EdgeGPT-GUI.py", line 34, in <module>
    root = ttk.Window()
  File "/Users/potapo/Library/Python/3.9/lib/python/site-packages/ttkbootstrap/window.py", line 231, in __init__
    self._icon = tkinter.PhotoImage(master=self, data=Icon.icon)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 4064, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 4009, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize image data
@cueavyqwp
Copy link
Owner

Hello, this error may be because of 'ttkbootstrap module

你好,这个报错可能是因为'ttkbootstrap'模块

Errors occur on line 34

错误出现在第34行

Please try to modify the code

请尝试修改代码

root = ttk.Window()
root.geometry( "1200x800" )
root.title( "EdgeGPT-GUI" )

找到第34行,并由上面的代码改为下面的代码

Find line 34 and change the code to the code below

root = tk.Window()
root.geometry( "1200x800" )
root.title( "EdgeGPT-GUI" )

Please try it. I hope it will help you

请尝试一下,希望对你有帮助

@cueavyqwp
Copy link
Owner

您好,以下是我询问Bing后得到的结果

Bing

您好,这是Bing。这个报错是因为tkinter.PhotoImage()只支持GIF和PGM/PPM等几种不常用的图片格式,而您的图片文件可能是JPG或PNG等其他格式。您可以尝试以下方法解决这个问题:

  • 将您的图片文件转换为GIF或PGM/PPM格式
  • 使用PIL库来读取和显示JPG或PNG等图片文件

希望对您有帮助!

User

可我的程序中并没任何图片加载的代码,难道是 "ttkbootstrap" 库的问题吗

Bing

您好,根据搜索结果,ttkbootstrap库是一个用于美化tkinter界面的库,它包含了一些使用base64编码的图片数据。可能是您的程序在使用ttkbootstrap时没有正确加载这些图片数据,导致报错。您可以尝试以下方法解决这个问题:

  • 确保您的程序中导入了tkinter.PhotoImage类,并用它来创建图片对象
  • 确保您的程序中指定了正确的ttkbootstrap主题名称,并且该主题包含了所需的图片数据
  • 如果您是使用pyinstaller打包您的程序,那么请确保将ttkbootstrap库中的themes.json和Symbola.ttf文件复制到与您的main.py和main.spec文件相同的文件夹,并在main.spec文件中添加datas= [ ('themes.json', 'ttkbootstrap'), ('Symbola.ttf', 'ttkbootstrap')]参数

希望对您有帮助!


所以,我认为,是您的 "ttkbootstrap" 库出了些问题
所以可以尝试禁用它

root = ttk.Window()
root.geometry( "1200x800" )
root.title( "EdgeGPT-GUI" )

改为

root = tk.Window()
root.geometry( "1200x800" )
root.title( "EdgeGPT-GUI" )

看看是否能解决问题

@WoodwindHu
Copy link
Author

这样也不行,AttributeError: module 'tkinter' has no attribute 'Window'

❯ python3 EdgeGPT-GUI.py
Traceback (most recent call last):
  File "/Users/potapo/github/EdgeGPT-GUI/EdgeGPT-GUI.py", line 34, in <module>
    root = tk.Window()
AttributeError: module 'tkinter' has no attribute 'Window'

@cueavyqwp
Copy link
Owner

抱歉是我的疏忽,应改为

root = tk.Tk()
root.geometry( "1200x800" )
root.title( "EdgeGPT-GUI" )

@WoodwindHu
Copy link
Author

我查了一下这好像是python不匹配Mac自带的tkinter的问题,我重新装一下python试试

@WoodwindHu
Copy link
Author

搞定了,中间出现了这个错误

❯ python EdgeGPT-GUI.py
Traceback (most recent call last):
  File "/Users/potapo/github/EdgeGPT-GUI/EdgeGPT-GUI.py", line 37, in <module>
    root.attributes( "-toolwindow" , 2 ) #只保留退出键
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 1976, in wm_attributes
    return self.tk.call(args)
_tkinter.TclError: bad attribute "-toolwindow": must be -alpha, -fullscreen, -modified, -notify, -titlepath, -topmost, -transparent, or -type

我把这一行注释了就好了

@cueavyqwp cueavyqwp pinned this issue Mar 21, 2023
@cueavyqwp cueavyqwp added the bug Something isn't working label Mar 21, 2023
@cueavyqwp cueavyqwp self-assigned this Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants