错误
Traceback (most recent call last):
File "c:\Users\User\Desktop\assignment testing\week8\2810 lab\gui\gui1 (1).py", line 18, in <module>
root.iconbitmap(r"c:/Users/User/Desktop/assignment testing/week8/2810 lab/gui")
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 2109, in wm_iconbitmap
return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
_tkinter.TclError: bitmap "c:/Users/User/Desktop/assignment testing/week8/2810 lab/gui" not defined
代码:
from tkinter import *
from tkinter import ttk
import tkinter as tk
from typing import Counter
from tkcalendar import Calendar, DateEntry
from PIL import ImageTk,Image
from tkinter import messagebox
import sqlite3;
#connect to databse
con = sqlite3.connect('Crash Statistics Victoria.db')
cur = con.cursor()
#root
root = Tk()
root.title('Accidents Analysis')
root.geometry("900x600")
root.iconbitmap(r"c:/Users/User/Desktop/assignment testing/week8/2810 lab/gui") //line 18
root.config(background = "#FFFFFF")```
删除```
root.config(background = "#FFFFFF")```
您尝试上传的图像可能不是 .ico,您需要确保其尺寸为 16x16、32x32、64x64 像素,这可能会有所帮助,尽管我不确定网上有很多只是 google - https:/ /convertio.co/jpg-ico/
root.iconbitmap(r"c:/Users/User/Desktop/assignment testing/week8/2810 lab/gui") //line 18
如果这没有帮助,那么我就不知道了,两天前我遇到了同样的问题,这是因为我没有 .ico 图标,所以对你来说可能会有所不同。
您的 iconbitmap 文件扩展名应该是 .ico、.png 或 .jpeg
如果问题仍然存在, 尝试在执行时添加 root.update()