当前位置:网站首页>Detour of Tkinter picture scaling
Detour of Tkinter picture scaling
2022-07-05 07:28:00 【work-harder】
background :
win8.1, python 3.9.7, Bring their own IDLE
Purpose :
stay canvas Show the complete picture in
Method :
On the whole , periphrasis , Not found yet tkinter Of PhotoImage How to zoom .
use PIL Of Image and ImageTk After detour , Submit it to canvas.create_image.
from tkinter import *
from PIL import Image # Installation method : pip install pillow, Name and PIL Different .
from PIL import ImageTk
class Application(Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.createWidget()
def createWidget(self):
self.canvas = Canvas(self, width=300,height=200, bg="green")
self.canvas.pack()
line = self.canvas.create_line(10,10,30,20,40,50)
rect = self.canvas.create_rectangle(50,50,100,100)
oval = self.canvas.create_oval(50,50,100,100)
global photo
#photo = PhotoImage(file="imgs/flowers.gif") # tkinter Of , Can't zoom
img1 = Image.open("imgs/flowers.gif")
img1 = img1.resize((200,100)) # The original image 3840x2160
photo = ImageTk.PhotoImage(image=img1,size=50) #PIL Of
self.canvas.create_image(200,150,image=photo)
#print("size of photo:{0},{1}".format(photo.width(), photo.height()))
# hold photo Switch to img1, You can see that img1 Picture size for
if __name__ == "__main__":
root = Tk()
root.geometry("400x300+200+200")
app = Application(master=root)
root.mainloop()
边栏推荐
- 玩转gRPC—深入概念与原理
- Implementation of one-dimensional convolutional neural network CNN based on FPGA (VIII) implementation of activation layer
- Simple operation of running water lamp (keil5)
- What if the DataGrid cannot see the table after connecting to the database
- ORACLE CREATE SEQUENCE,ALTER SEQUENCE,DROP SEQUENCE
- 2022.06.27_ One question per day
- Raspberry pie 4B arm platform aarch64 PIP installation pytorch
- Explanation of parallel search set theory and code implementation
- And let's play dynamic proxy (extreme depth version)
- What is soda?
猜你喜欢
IPage can display data normally, but total is always equal to 0
[software testing] 02 -- software defect management
[software testing] 04 -- software testing and software development
SOC_ SD_ DATA_ FSM
Anaconda navigator click open no response, can not start error prompt attributeerror: 'STR' object has no attribute 'get‘
When jupyter notebook is encountered, erroe appears in the name and is not output after running, but an empty line of code is added downward, and [] is empty
Line test -- data analysis -- FB -- teacher Gao Zhao
玩转gRPC—深入概念与原理
UE5热更新-远端服务器自动下载和版本检测(SimpleHotUpdate)
并查集理论讲解和代码实现
随机推荐
arcpy. SpatialJoin_ Analysis spatial connection analysis
[framework] multi learner
Unconventional ending disconnected from the target VM, address: '127.0.0.1:62635', transport: 'socket‘
SD_ CMD_ RECEIVE_ SHIFT_ REGISTER
Shadowless cloud desktop - online computer
Idea common settings
GBK error in web page Chinese display (print, etc.), solution
Oracle code use
Powermanagerservice (I) - initialization
U-boot initialization and workflow analysis
Implementation of one-dimensional convolutional neural network CNN based on FPGA (VIII) implementation of activation layer
What is sodium hydroxide?
Import CV2 prompt importerror: libgl so. 1: Cannot open shared object file: no such file or directory
Anaconda navigator click open no response, can not start error prompt attributeerror: 'STR' object has no attribute 'get‘
Idea shortcut key
Simple operation of nixie tube (keil5)
ImportError: No module named ‘Tkinter‘
Line test -- data analysis -- FB -- teacher Gao Zhao
The mutual realization of C L stack and queue in I
What if the DataGrid cannot see the table after connecting to the database