当前位置:网站首页>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()
边栏推荐
- Matrix and TMB package version issues in R
- Now there are HTML files and MVC made with vs (connected to the database). How can they be connected?
- [vscode] recommended plug-ins
- 行测--资料分析--fb--高照老师
- Negative number storage and type conversion in programs
- [untitled]
- Database SQL practice 4. Find the last of employees in all assigned departments_ Name and first_ name
- Ugnx12.0 initialization crash, initialization error (-15)
- Line test -- data analysis -- FB -- teacher Gao Zhao
- Basic series of SHEL script (III) for while loop
猜你喜欢

Import CV2 prompt importerror: libgl so. 1: Cannot open shared object file: no such file or directory

C#学习笔记

Target detection series - detailed explanation of the principle of fast r-cnn

PostMessage communication
![[software testing] 04 -- software testing and software development](/img/bd/49bba7ee455ce59e726a2fdeafc7c3.jpg)
[software testing] 04 -- software testing and software development

行测--资料分析--fb--高照老师

Don't confuse the use difference between series / and / *

M2DGR 多源多场景 地面机器人SLAM数据集

CADD course learning (6) -- obtain the existing virtual compound library (drugbank, zinc)
![[software testing] 06 -- basic process of software testing](/img/fe/3d8b9b68f95ac7899ab87d6993284d.jpg)
[software testing] 06 -- basic process of software testing
随机推荐
Cookie operation
Word import literature -mendeley
ImportError: No module named ‘Tkinter‘
Ugnx12.0 initialization crash, initialization error (-15)
使用go语言读取txt文件写入excel中
The difference between NPM install -g/-save/-save-dev
Ethtool principle introduction and troubleshooting ideas for network card packet loss (with ethtool source code download)
I 用c I 实现队列
Light up the running light, rough notes for beginners (1)
Simple operation of nixie tube (keil5)
And play the little chestnut of dynamic agent
GPIO port bit based on Cortex-M3 and M4 with operation macro definition (can be used for bus input and output, STM32, aducm4050, etc.)
Intelligent target detection 59 -- detailed explanation of pytoch focal loss and its implementation in yolov4
CADD课程学习(6)-- 获得已有的虚拟化合物库(Drugbank、ZINC)
Batch convert txt to excel format
How to deal with excessive memory occupation of idea and Google browser
Simple use of timeunit
【Node】npm、yarn、pnpm 区别
DelayQueue延迟队列的使用和场景
Energy conservation and creating energy gap