Python tkinter GUI drawing, and click to update Display picture

Source: Internet
Author: User

Tkinter drawing GUI is simple and clear, make some simple GUI enough, currently encountered a problem is not to display multiple pictures at the same time (not found at the same time to display the solution),

Back to the second, change to add an Update button, each time the button to update the image automatically, the comment out of the original kernel package, replaced by their own program can be

ImportTkinter as TK fromTkinterImport* fromTkinterImportTTK fromUrllib.requestImportUrlopen fromPILImportImage, IMAGETK#Import make_pic_2 importing its own PY package file hereNum=1URL="./picture/rain.png"defCalculate (*args):Print(Addr.get (),":", Port.get ())#make_pic_2.main (int (Fft.get ()), int (Start.get ()), int (Stop.get ()), int (Cent.get () ))#call your own kernel functiondefChange ():#Update picture Operations    GlobalNum Num=num+1ifnum%3==0:URL1="./picture/rain.png"Pil_image=image.open (URL1) img=imagetk.photoimage (pil_image) label_img.configure (Image=img)ifNum%3==1: Url1="./picture/oscillogram.png"Pil_image=image.open (URL1) img=imagetk.photoimage (pil_image) label_img.configure (Image=img)ifnum%3==2: Url1="./picture/spectrum.png"Pil_image=image.open (URL1) img=imagetk.photoimage (pil_image) label_img.configure (Image=img) root.update_idletasks ()#to update a picture, you must updateRoot=Tk () root.title ("Draw GUI") Mainframe= TTK. Frame (Root, padding="5 4") mainframe.grid (column=0, Row=0, sticky=(N, W, E, S)) mainframe.columnconfigure (0, weight=1) mainframe.rowconfigure (0, weight=1) Addr=stringvar () port=stringvar () FFT=stringvar () cent=stringvar () Start=stringvar () Stop=stringvar () ttk. Label (mainframe, text="Address:"). Grid (Column=1, Row=1, sticky=W) Addr_entry= TTK. Entry (Mainframe, width=7, textvariable=addr) addr_entry.grid (column=2, Row=1, sticky=(W, E)) TTK. Label (mainframe, text="Port:"). Grid (Column=3, Row=1, sticky=W) Port_entry= TTK. Entry (Mainframe, width=7, textvariable=port) Port_entry.grid (column=4, Row=1, sticky=(W, E)) TTK. Label (mainframe, text="FFt:"). Grid (Column=1, row=2, sticky=W) Fft_entry= Ttk.combobox (mainframe, width=7, textvariable=FFT) fft_entry['Values'] = (2048, 4096, 8192) fft_entry.current (1) fft_entry.grid (column=2, row=2, sticky=(W, E)) TTK. Label (mainframe, text="CENTERFR:"). Grid (Column=3, row=2, sticky=W) Cent_entry= TTK. Entry (Mainframe, width=7, textvariable=cent) Cent_entry.grid (column=4, row=2, sticky=(W, E)) TTK. Label (mainframe, text="STARTFR:"). Grid (Column=1, row=3, sticky=W) Start_entry= TTK. Entry (Mainframe, width=7, textvariable=start) start_entry.grid (column=2, Row=3, sticky=(W, E)) TTK. Label (mainframe, text="STOPFR:"). Grid (Column=3, row=3, sticky=W) Stop_entry= TTK. Entry (Mainframe, width=7, textvariable=stop) stop_entry.grid (column=4, Row=3, sticky=(W, E)) TTK. Button (mainframe, text="draw!", command=calculate). Grid (column=2, row=4, sticky=W) TTK. Button (mainframe, text="update!", Command=change). Grid (Column=4, row=4, sticky=W) Pil_image=image.open (URL) img=imagetk.photoimage (pil_image) label_img= TTK. Label (root, Image = img, compound=CENTER) label_img.grid (column=0,row=5, sticky=W) forChildinchMainframe.winfo_children (): Child.grid_configure (padx=5, pady=5) Addr_entry.focus () Root.bind ('<Return>', calculate)#The main loop, except that the line can be looped all the time, and the other rows are executed only onceRoot.mainloop ()

Python tkinter GUI drawing, and click to update Display picture

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.