簡體   English   中英

當我嘗試設置我的徽標時,Python tkinter 給我一個錯誤(GUI WINDOW)

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

當我嘗試添加圖像並將其設置為我的 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

我已經使用代碼更改了文件類型。

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()

為此,您將需要枕頭庫。

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()

注意:最好直接導入庫:運行

import tkinter

代替

from tkinter import *

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM