简体   繁体   English

当我尝试设置我的徽标时,Python tkinter 给我一个错误(GUI WINDOW)

[英]Python tkinter giving me an error when I try to set me logo (GUI WINDOW)

When I try to add an image and set it as my GUI window logo it gives me these errors当我尝试添加图像并将其设置为我的 GUI 窗口徽标时,它给了我这些错误

Traceback (most recent call last):
  File "C:\Users\Meina Jia\PycharmProjects\guwindow\main.py", line 7, in <module>
    icon = PhotoImage(file='logo.jpg')
  File "C:\Users\Meina Jia\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 4093, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "C:\Users\Meina Jia\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 4038, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "logo.jpg"

Process finished with exit code 1

I already changed the file type using code.我已经使用代码更改了文件类型。

from tkinter import *

window = Tk()
window.geometry("420x420")
window.title("Backrooms in A Nutshell")

icon = PhotoImage(file='logo.jpg')
window.iconphoto(True, icon)

window.mainloop()

For this, you will need the Pillow Library.为此,您将需要枕头库。

import tkinter as tk
from PIL import ImageTk, Image
window = tk.Tk()
window.geometry("420x420")
window.title("Backrooms in A Nutshell")

icon = ImageTk.PhotoImage(Image.open('logo.jpg'))
window.iconphoto(True, icon)


window.mainloop()

Note: It is good practice to import a library directly: Run注意:最好直接导入库:运行

import tkinter

instead of代替

from tkinter import *

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我用python 3 tkinter编写了这段代码代码,它给了我一个错误 - I wrote this code a code with python 3 tkinter and it's giving me an error 当我尝试运行它时,Tkinter 给了我一个 _tkinter.TclError: bad event type or keysym &quot;button&quot; - Tkinter is giving me a _tkinter.TclError: bad event type or keysym "button" when i try to run it 当我尝试连接-python时,套接字给我错误 - Socket gives me error when i try to connect -python 我正在使用 tkinter 在 python 中创建测验,但是当我尝试获得分数时,它没有给我分数 - I am using tkinter to create quiz in python, but when i try to get the score, it does not give me the score 当字体不是一个单词时,更改画布中的字体样式给我一个错误python Tkinter - Changing font style in canvas is giving me a error when font is not one word python Tkinter 当我尝试使用.open时,Python Mechanize一直给我&#39;response_seek_wrapper&#39; - Python Mechanize keeps giving me 'response_seek_wrapper' when I try to use .open 当我尝试导入 pandas 时,我的 Python 控制台不断给我错误 - My Python console keeps giving me errors when I try to import pandas 使用 try 语句,但给我语法错误 - Using try statement, but giving me syntax error Python Quandl 给我错误 - Python Quandl giving me error Python 3 和 GUI Tkinter 标志插入 - Python 3 and GUI Tkinter logo insertion
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM