当前位置:网站首页>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()
边栏推荐
- Mathematical analysis_ Notes_ Chapter 8: multiple integral
- 【idea】Could not autowire. No beans of xxx type found
- Basic series of SHEL script (III) for while loop
- Anaconda navigator click open no response, can not start error prompt attributeerror: 'STR' object has no attribute 'get‘
- HDU1231 最大连续子序列(分治or动规or双指针)
- Light up the running light, rough notes for beginners (1)
- 行测--资料分析--fb--高照老师
- Intelligent target detection 59 -- detailed explanation of pytoch focal loss and its implementation in yolov4
- 2022.06.27_每日一题
- SOC_ SD_ DATA_ FSM
猜你喜欢

Graduation thesis project local deployment practice

2022 PMP project management examination agile knowledge points (7)

I implement queue with C I

Daily Practice:Codeforces Round #794 (Div. 2)(A~D)

借助 Navicat for MySQL 软件 把 不同或者相同数据库链接中的某数据库表数据 复制到 另一个数据库表中

Ue5 hot update - remote server automatic download and version detection (simplehotupdate)

【idea】Could not autowire. No beans of xxx type found

611. 有效三角形的个数

Idea common settings

Do you choose pandas or SQL for the top 1 of data analysis in your mind?
随机推荐
The SQL implementation has multiple records with the same ID, and the latest one is taken
[software testing] 04 -- software testing and software development
[vscode] recommended plug-ins
并查集理论讲解和代码实现
Basic series of SHEL script (I) variables
What does soda ash do?
arcpy. SpatialJoin_ Analysis spatial connection analysis
[software testing] 05 -- principles of software testing
Machine learning Seaborn visualization
[node] NVM version management tool
Brief description of inux camera (Mipi interface)
Reading literature sorting 20220104
What is sodium hydroxide?
611. Number of effective triangles
Matrix keyboard scan (keil5)
Idea to view the source code of jar package and some shortcut keys (necessary for reading the source code)
How to deal with excessive memory occupation of idea and Google browser
(top) pretty girl binary color code portal
Database SQL practice 4. Find the last of employees in all assigned departments_ Name and first_ name
Concurrent programming - deadlock troubleshooting and handling