首页 > 解决方案 > 屏幕尺寸与 Python tkinter 中的窗口尺寸一致

问题描述

我在 Python Tkinter 中的屏幕配置有问题。我想要一个与我打开它的窗口大小兼容的壁纸。我做了这个功能:

def resizer(e):
    global bg1, resized_bg, new_bg
    bg1 = Image.open("WUT_banner_Automotive_1080x335.4532699.png")
    resized_bg = bg1.resize((e.width, e.height), Image.ANTIALIAS)
    new_bg = ImageTk.PhotoImage(resized_bg)
    my_canvas.create_image(0,0, image=new_bg, anchor="nw")

当我在“main”中调用它时效果很好,但是当我在另一个函数中调用它时它不起作用:

def log_ok():
    user = e1.get()
    password = e2.get()

    if(user == "" and password == ""):
        messagebox.showinfo("", "Inserisci le credenziali per accedere.")

    elif(user == "admin" and password == "admin"):
        messagebox.showinfo("", "Login success.")
        root.destroy()
        s = Tk()
        s.title("Service window")
        s.geometry("700x400")
        bg = ImageTk.PhotoImage(file="WUT_banner_Automotive_1080x335.4532699.png")
        my_canvas = Canvas(s, width = 700, heigh =335)
        my_canvas.pack(fill="both", expand=True)
        my_canvas.create_image(0,0, image=bg, anchor="nw")
        Button(s, text="Diagnostic request", command = lambda: [ s.destroy(),open_window() ] , heigh = 3, width = 13).place(x=10, y=100)




        .bind('<Configure>', resizer)
        s.mainloop()
    
       
        
        

    else:
        messagebox.showerror("", "Incorrect Username and Password")`

特别是,我收到此错误: 在此处输入图像描述

你能告诉我我哪里错了吗?我看不到错误,近两天来我一直在思考如何制作适合窗户但在另一个功能中的墙纸。任何帮助将不胜感激。

标签: pythontkinterpython-idle

解决方案


推荐阅读