1
我正在编写一个辛普森琐事游戏作为我的第一个大型编程项目。我的问题是双重的:tkinter窗口和背景图像不正确对齐
- 这是创建背景图片的正确方法吗?请记住,我的计划是在背景中包含辛普森一家主题曲以及背景图片顶部的一个或两个按钮。
- 假设下面的代码是我想要完成的正确方法,为什么我的图像和窗口左侧会出现细灰线? IE浏览器。为什么图像没有像在右侧那样完美地填满窗户?
这里是我的代码:
from tkinter import *
from tkinter import ttk
from PIL import Image, ImageTk
root = Tk()
root.title("The Simpsons Trivia Game")
root.geometry('400x600')
root.resizable(0,0)
def resize_image(event):
new_width = event.width
new_height = event.height
image = copy_of_image.resize((new_width, new_height))
photo = ImageTk.PhotoImage(image)
label.config(image = photo)
label.image = photo
image = Image.open('E:\Simpsons Trivia Game\SimpsonsPic.png')
copy_of_image = image.copy()
photo = ImageTk.PhotoImage(image)
label = ttk.Label(root, image = photo)
label.bind('<Configure>', resize_image)
label.pack(fill=BOTH, expand = YES)
root.mainloop()