当前位置:网站首页>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()
边栏推荐
- Target detection series - detailed explanation of the principle of fast r-cnn
- CADD course learning (6) -- obtain the existing virtual compound library (drugbank, zinc)
- SD_ CMD_ RECEIVE_ SHIFT_ REGISTER
- 1290_ Implementation analysis of prvtaskistasksuspended() interface in FreeRTOS
- What is sodium hydroxide?
- D2L installation
- Database SQL practice 3. Find the current salary details of the current leaders of each department and their corresponding department number Dept_ no
- DataGrid offline installation of database driver
- How to modify the file path of Jupiter notebook under miniconda
- Basic series of SHEL script (I) variables
猜你喜欢
Solve tensorfow GPU modulenotfounderror: no module named 'tensorflow_ core. estimator‘
CADD课程学习(5)-- 构建靶点已知的化合结构(ChemDraw)
I 用c l 栈与队列的相互实现
Set theory of Discrete Mathematics (I)
Light up the running light, rough notes for beginners (1)
2022年PMP项目管理考试敏捷知识点(7)
Idea common settings
M2dgr slam data set of multi-source and multi scene ground robot
[software testing] 06 -- basic process of software testing
Jenkins reported an error. Illegal character: '\ufeff'. Class, interface or enum are required
随机推荐
How to deal with excessive memory occupation of idea and Google browser
[vscode] search using regular expressions
氫氧化鈉是什麼?
Detailed explanation of miracast Technology (I): Wi Fi display
Intelligent target detection 59 -- detailed explanation of pytoch focal loss and its implementation in yolov4
[software testing] 02 -- software defect management
Cookie operation
How to delete the virus of inserting USB flash disk copy of shortcut to
Idea common settings
I implement queue with C I
How to modify the file path of Jupiter notebook under miniconda
Unconventional ending disconnected from the target VM, address: '127.0.0.1:62635', transport: 'socket‘
Word import literature -mendeley
【Node】nvm 版本管理工具
C learning notes
借助 Navicat for MySQL 软件 把 不同或者相同数据库链接中的某数据库表数据 复制到 另一个数据库表中
Mathematical analysis_ Notes_ Chapter 8: multiple integral
Selenium element positioning
2022年PMP项目管理考试敏捷知识点(7)
The difference between NPM install -g/-save/-save-dev