Home > other >  About the Label in tkinter after initial size and configuration picture size Settings
About the Label in tkinter after initial size and configuration picture size Settings

Time:05-08

Initial set the width and height of the Label, button, as shown on the Label images, at the same time set the size of the image, the image size displays wrong, delete the Label on the initial setup of width and height, is this why? But still need to set the initial size of the Label, so this size problem how to solve?
Then the size of the unit before and after seems to be different?
 import tkinter as tk 
The from PIL import Image, ImageTk

The class test (tk. Tk) :
Def __init__ (self) :
Super (test, self) __init__ ()

Self. Label=tk. Label (self, width=100, height=10, text='this is an innocent label') # initial setup the label width and height of the
The self. The label. The pack ()

The self. The button=tk. The button (self, text='innocent button, the command=self. Show_img)
The self. The button. The pack ()

Def show_img (self) :
Img_open=Image. Open (' images')
Resized=img_open. Resize ((600, 700), the Image. The ANTIALIAS) # set the Image size
Img=ImageTk. PhotoImage (resized)
The self. The label. The config (image=img)
The self. The label. The image=img

If __name__=="__main__ ':
GUI=test ()
GUI. Mainloop ()

For help, meowed, save the children
  • Related