我的目标是创建一个随机的国家发电机,并挑选国家的国旗会出现。但是,如果图像文件大于标签的预定大小,则只显示部分图像。有没有调整图像大小以适应标签的方法? (这样,其他所有问题,我所看到的已经回答了,提PIL或图片模块我测试了他们两个,他们都想出了这个错误:如何调整图像大小以适应标签大小? (蟒蛇)
回溯(最近通话最后一个): 文件“C:\蟒蛇\ country.py”,第6行,在 进口PIL 导入错误:没有模块名为 '太平'
这是我的代码,如果它可以帮助:
import tkinter
from tkinter import *
import random
flags = ['England','Wales','Scotland','Northern Ireland','Republic of Ireland']
def newcountry():
country = random.choice(flags)
flagLabel.config(text=country)
if country == "England":
flagpicture.config(image=England)
elif country == "Wales":
flagpicture.config(image=Wales)
elif country == "Scotland":
flagpicture.config(image=Scotland)
elif country == "Northern Ireland":
flagpicture.config(image=NorthernIreland)
else:
flagpicture.config(image=Ireland)
root = tkinter.Tk()
root.title("Country Generator")
England = tkinter.PhotoImage(file="england.gif")
Wales = tkinter.PhotoImage(file="wales.gif")
Scotland = tkinter.PhotoImage(file="scotland.gif")
NorthernIreland = tkinter.PhotoImage(file="northern ireland.gif")
Ireland = tkinter.PhotoImage(file="republic of ireland.gif")
blackscreen = tkinter.PhotoImage(file="black screen.gif")
flagLabel = tkinter.Label(root, text="",font=('Helvetica',40))
flagLabel.pack()
flagpicture = tkinter.Label(root,image=blackscreen,height=150,width=150)
flagpicture.pack()
newflagButton = tkinter.Button(text="Next Country",command=newcountry)
newflagButton.pack()
代码除了仅展示我的一部分之外,它的工作非常好法师。有没有办法代码本身内调整图像?(我使用Python 3.5.1)