In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "how to use Python to draw graphics in tkinter". The editor shows you the process of operation through an actual case. The method of operation is simple and fast, and it is practical. I hope that this article "how to achieve Python in tkinter using matplotlib to draw graphics" can help you solve the problem.
one。 Code:
# coding=utf-8
Importsys
ImportTkinterasTk
Importmatplotlib
Fromnumpyimportarange,sin,pi
From Matt Lotley. Back end. Backend _ Tkaggimportfigures extensible tag, Navigation Toolbar 2 tag
Frommatplotlib . Backend _ basesimportkey_press_handler
From Matt Lotley. Diagram import diagram
Matplotlib.use ('TkAgg')
Root=Tk .TK ()
Huawei Cloud Test-matplotlibinTK')
# set drawing size and quality
F = number (figsize= (5) 4), dpi=100)
A=f.add_subplot (111)
T=arange (0. 0d3. 0. 01)
S=sin (2*pi*t)
# drawing graphics
A. Drawing (tmeme s)
# display the drawn graphics on the graphical interface window
CanvastKaggg (fjore mastery root)
Canvas.show ()
Canvas.get_tk_widget (). Packing (side = Tk. Top, fill=Tk. Both, expand = 1)
# display the navigation toolbar with beautifully drawn charts and graphs to the graphical interface window
Toolbar = Navigation Toolbar 2 label (canvas, root)
Toolbar. Update ()
Canvas. Tkcanvas.pack (side=Tk. Top, fill=Tk. Both, expand = 1)
# define and bind keyboard event handlers
Defon_key_event (event):
Print ('you pressed% s'% event. Key ")
Key_press_handler (event, canvas, toolbar)
Canvas. Mpl _ connect ('key_ press _ event', on_key_event)
# Button Click event handler
Def_quit ():
# end the main loop of the event and destroy the application window
Root.quit ()
Root.destroy ()
Button=Tk. Button (main = root, text = 'exit, command = _ exit)
Button.pack (side=Tk. Bottom)
Main circuit (II. Running result:)
This is the end of the introduction on "how to use Python to draw graphics with matplotlib in tkinter". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.