位图无法定义图标文件

问题描述 投票:0回答:1

我使用位图功能来清除“.ico”文件,但这是同样的问题。 这是我的代码:

class Login:
    def __init__(self, window):
        self.master = window
        self.master.title("Login System")
        self.master.geometry("500x500+150+150")
        self.img = Image.open('loginImage.png')
        self.img.thumbnail((200, 200))
        self.new_img = ImageTk.PhotoImage(self.img)
        self.imgStudent = Label(self.master, image=self.new_img)
        self.imgStudent.pack()
        self.frameLogin = Frame(self.master)
        self.frameLogin.pack()
        self.labelUser = Label(self.frameLogin, text='Username', pady=10, padx=10, font=('tahoma', 10, 'bold'))
        self.labelUser.grid(row=0, column=0)
        self.labelPass = Label(self.frameLogin, text='Password', pady=10, padx=10, font=('tahoma', 10, 'bold'))
        self.labelPass.grid(row=1, column=0)
        self.username = Entry(self.frameLogin, font=('tahoma', 10, 'bold'))
        self.username.grid(row=0, column=1, pady=10, padx=10)
        self.password = Entry(self.frameLogin, font=('tahoma', 10, 'bold'), show="*")
        self.password.grid(row=1, column=1, pady=10, padx=10)
        self.LoginButton = Button(self.frameLogin, command=self.login, text='Login', font=('tahoma', 10, 'bold'),
                                  bg='#1b9ea4', fg='white', cursor='cross')
        self.LoginButton.grid(row=2, column=0, columnspan=2, sticky='snew', pady=10, padx=10)

    def login(self):
            mydb = mc.connect(
            host='localhost',
            user='root',
            password='',
            database='university'
            )

            mycursor = mydb.cursor()
            sql = "select * from loginadmin where Username='" + self.username.get() + "' and Password='" + self.password.get() + "'"
            mycursor.execute(sql)
            res = mycursor.fetchone()
            if (res == None):
                mb.showerror('Failed Login', 'Invalid Username and Password ! please Try again')
            else:
                win = Toplevel()
                win.iconbitmap('swim_ring_icon_183313.ico')
                window = University(win)




if (__name__ == '__main__'):
    window = Tk()
    window.iconbitmap('swim_ring_icon_183313.ico')
    std = Login(window)

    mainloop()

这是完全错误: 回溯(最近一次调用最后一次): 文件“C:\universitymanagementsystem-main\universitymanagementsystem-main\main.py”,第 1019 行,位于 window.iconbitmap('swim_ring_icon_183313.ico') 文件“C:\Users\Humam\AppData\Local\Programs\Python\Python311\Lib kinter_init_.py”,第 2136 行,在 wm_iconbitmap 中 返回 self.tk.call('wm', 'iconbitmap', self._w, 位图) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ _tkinter.TclError:位图“swim_ring_icon_183313.ico”未定义

我尝试使用Image功能,将照片格式改为png,还是一样。

python tkinter
1个回答
0
投票

这应该如何识别-> ''' lang_python window.iconbitmap('图片/swim_ring_icon_183313.ico') '''

© www.soinside.com 2019 - 2024. All rights reserved.