Image Größenänderung und passen Sie es an die Leinwandgröße an

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Image Größenänderung und passen Sie es an die Leinwandgröße an

by Anonymous » 29 Jul 2025, 04:03

Kann mir jemand helfen, das Bild mit Imagetk zu ändern? Anteil. < /p>
Bitte helfen Sie mir! Ich bin neu in Pil, Tkinter und Python.

Code: Select all

self.image.thumbnail(self.picsize,Image.ANTIALIAS)
Das Bild passt nicht zur Leinwandgröße und wenn das Bild länger/breiter ist als die Leinwand, wird es nur geschnitten. (Die Größe nicht in die Leinwand einpasst) < /p>

Code: < /p>

Code: Select all

from PIL import ImageTk
from Tkinter import *
import os,tkFileDialog,Image

picsize = 250,250 # I want to set this so that it will fit in the self.imagecanvas | Every images attached will share same Size
imagepath = "Default_ProPic.jpg"
class GUI():
global picsize
def display(self):
self.canvas = Canvas(width=1200,height=700)
self.canvas.pack()

self.imagecanvas = Canvas(self.canvas,width=400,height=400)
self.imagecanvas.place(x=980,y=180)
self.image = Image.open(imagepath)
self.image.thumbnail(picsize,Image.ANTIALIAS)
self.newimage = ImageTk.PhotoImage(self.image)
self.profile_picture=self.imagecanvas.create_image(0,0,anchor = NW,image=self.newimage)

attachbutton = Button(self.canvas,text="       Profile Pic       ",command=lambda:self.attachpic())
attachbutton.place(x=1030,y=320)

mainloop()

def attachpic(self):
global picsize
attachphoto = tkFileDialog.askopenfilename(title="Attach photo")
self.image = Image.open(attachphoto)
self.image.thumbnail(picsize,Image.ANTIALIAS)
self.newimage = ImageTk.PhotoImage(self.image)
self.imagecanvas.itemconfigure(self.profile_picture, image=self.newimage)

GUI = GUI()
GUI.display()
Bild verwendet:

Top