当前位置:网站首页>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
- Use go language to read TXT file and write it into Excel
- 【Node】npm、yarn、pnpm 区别
- I 用c l 栈与队列的相互实现
- Hdu1231 maximum continuous subsequence (divide and conquer or dynamic gauge or double pointer)
- IPage can display data normally, but total is always equal to 0
- [vscode] prohibit the pylance plug-in from automatically adding import
- Light up the running light, rough notes for beginners (1)
- Matrix keyboard scan (keil5)
- 行测--资料分析--fb--高照老师
猜你喜欢
Brief description of inux camera (Mipi interface)
剑指 Offer 56 数组中数字出现的次数(异或)
Machine learning Seaborn visualization
Do you choose pandas or SQL for the top 1 of data analysis in your mind?
How to modify the file path of Jupiter notebook under miniconda
The mutual realization of C L stack and queue in I
Explanation of parallel search set theory and code implementation
Solve tensorfow GPU modulenotfounderror: no module named 'tensorflow_ core. estimator‘
Delayqueue usage and scenarios of delay queue
第 2 章:小试牛刀,实现一个简单的Bean容器
随机推荐
SD_ CMD_ SEND_ SHIFT_ REGISTER
Batch convert txt to excel format
Clickhouse database installation deployment and remote IP access
Idea push project to code cloud
1290_ Implementation analysis of prvtaskistasksuspended() interface in FreeRTOS
Target detection series - detailed explanation of the principle of fast r-cnn
Simple operation of running water lamp (keil5)
611. 有效三角形的个数
Don't confuse the use difference between series / and / *
Reading literature sorting 20220104
Unconventional ending disconnected from the target VM, address: '127.0.0.1:62635', transport: 'socket‘
Powermanagerservice (I) - initialization
Simple use of timeunit
Explanation of parallel search set theory and code implementation
Self summary of college life - freshman
What is soda?
list. files: List the Files in a Directory/Folder
QT small case "addition calculator"
The number of occurrences of numbers in the offer 56 array (XOR)
Today, share the wonderful and beautiful theme of idea + website address