python - 屏幕尺寸与 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")`
特别是,我收到此错误: 在此处输入图像描述
你能告诉我我哪里错了吗?我看不到错误,近两天来我一直在思考如何制作适合窗户但在另一个功能中的墙纸。任何帮助将不胜感激。
解决方案
推荐阅读
- postgresql - 为什么 Perl DBI 接口无法插入到 Postgres 表?
- c# - Entity Framework Core - 如何在更改跟踪器中识别根实体
- python - django 模型是否支持多个 slug?
- android-studio - 我的一个项目的模拟器上有多个应用程序
- android - Firebase MLKit QRCode 扫描失败,没有错误堆栈跟踪
- ios - Flutter 应用程序在 ios 模拟器中运行时总是崩溃
- python - 使用 bs4 的 Python webscrape 跳过了第一项,但其余的都很好
- google-apps-script - Google Sheets onEdit - 尝试通过更改同一行中列的值将一行复制到新工作表
- python - 如何更好地定位颜色条?
- scala - 为什么对模板类的两个成员进行 + 操作会导致类型不匹配错误?