Mein Ziel ist es, einen zufälligen Landgenerator zu erstellen, und die Flagge des Landes, das ausgewählt wird, wird angezeigt. Wenn die Bilddatei jedoch größer als die vorbestimmte Größe des Etiketts ist, wird nur ein Teil des Bildes angezeigt. Gibt es eine Möglichkeit, das Bild an das Etikett anzupassen? . (Alle anderen Fragen wie diese, die ich gesehen habe, sind beantwortet worden, die PIL oder Bild Module Erwähnens Getestet habe ich sie beide, und beide kamen mit diesem Fehler auf:Wie wird ein Bild an die Größe des Etiketts angepasst? (python)
Traceback (jüngste Aufforderung zuletzt): Datei "C: \ python \ country.py", Zeile 6, in Import PIL Import: Kein Modul namens 'PIL'
Dies ist mein Code, wenn es hilft:
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()
Der Code funktioniert vollkommen in Ordnung, abgesehen davon, dass nur ein Teil des i Magier. Gibt es eine Möglichkeit, die Bilder innerhalb des Codes selbst, um die Größe? (Ich verwende Python 3.5.1)