【发布时间】:2016-12-05 11:03:35
【问题描述】:
我正在编写一个辛普森一家琐事游戏作为我的第一个大型编程项目。我的问题是双重的:
- 这是创建背景图像的正确方法吗?请记住,我的计划是包括在背景中播放的辛普森一家主题曲以及背景图像顶部的一两个按钮。
- 假设下面的代码是我想要完成的正确方法,为什么我的图像和窗口左侧出现一条细灰线? 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()
【问题讨论】:
标签: python tkinter python-3.4