当前位置:网站首页>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()
边栏推荐
- Three body goal management notes
- Basic series of SHEL script (II) syntax + operation + judgment
- Matrix keyboard scan (keil5)
- Self summary of college life - freshman
- ORACLE CREATE SEQUENCE,ALTER SEQUENCE,DROP SEQUENCE
- DataGrid offline installation of database driver
- 行测--资料分析--fb--高照老师
- The SQL implementation has multiple records with the same ID, and the latest one is taken
- 【idea】Could not autowire. No beans of xxx type found
- 611. Number of effective triangles
猜你喜欢

Pytorch has been installed in anaconda, and pycharm normally runs code, but vs code displays no module named 'torch‘
![[software testing] 03 -- overview of software testing](/img/1e/0b6458160e34e43f021ea4797de70a.jpg)
[software testing] 03 -- overview of software testing
![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](/img/fe/fb6df31c78551d8908ba7964c16180.jpg)
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

The problem of configuring opencv in qt5.13.2 is solved in detail

And let's play dynamic proxy (extreme depth version)

Solve tensorfow GPU modulenotfounderror: no module named 'tensorflow_ core. estimator‘

Ethtool principle introduction and troubleshooting ideas for network card packet loss (with ethtool source code download)

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

Microservice registry Nacos introduction

Don't confuse the use difference between series / and / *
随机推荐
目标检测系列——Faster R-CNN原理详解
Simple use of timeunit
How to modify the file path of Jupiter notebook under miniconda
SD_ CMD_ RECEIVE_ SHIFT_ REGISTER
DelayQueue延迟队列的使用和场景
Now there are HTML files and MVC made with vs (connected to the database). How can they be connected?
Self summary of college life - freshman
Line test -- data analysis -- FB -- teacher Gao Zhao
Cookie operation
Ugnx12.0 initialization crash, initialization error (-15)
公安专业知识--哔哩桐老师
QT small case "addition calculator"
Play with grpc - go deep into concepts and principles
Three body goal management notes
Microservice registry Nacos introduction
剑指 Offer 56 数组中数字出现的次数(异或)
Implementation of one-dimensional convolutional neural network CNN based on FPGA (VIII) implementation of activation layer
Install deeptools in CONDA mode
Today, share the wonderful and beautiful theme of idea + website address
M2dgr slam data set of multi-source and multi scene ground robot