Python3 graphical Interface Simple case (Tkinter)

Source: Internet
Author: User

1. For the use of dialog boxes in Python3:

Note that there are a lot of changes in python3 relative to Python2, some of which are changed by the name of the Tkinter, which changes to Tkinter, and the dialog box can be used by importing python2 in Tkmessagebox, for example:
Tkmessagebox.showifo ("MessageBox", "This is a MessageBox")

This module has become MessageBox in Python3, and we only need to import Tkinter.messagebox to use (tk = TK ()):

Tk.messagebox.showinfo ("MessageBox", "This is a MessageBox")

Refer to the case:

From tkinter Import * Import Tkinter.messagebox class Mainwindow:def ButtonListener1 (self,event): TKINTER.M Essagebox.showinfo ("MessageBox", "This is Button 1 dialog") def buttonListener2 (self,event): Tkinter.messagebox . Showinfo ("MessageBox", "This is button 2 Dialog") def buttonListener3 (self,event): Tkinter.messagebox.showinfo (' MessageBox ', ' This is button 3 dialog ') def buttonListener4 (self,event): Tkinter.messagebox.showinfo ("message Box "," This is button 4 Dialog ") def __init__ (self): Self.frame = Tk () self.button1 = button (Self.frame,text = "Button1", Width = 10,height = 5) Self.button2 = button (Self.frame,text = "Button2", Width = 10,h eight = 5) Self.button3 = button (Self.frame,text = "Button3", width = 10,height = 5) Self.button4 = button (
        Self.frame,text = "Button4", width = 10,height = 5) self.button1.grid (row = 0,column = 0,PADX = 5,pady = 5) Self.button2.grid (row= 0,column = 1,PADX = 5,pady = 5) self.button3.grid (row = 1,column = 0,PADX = 5,pady = 5) Self.button4.gri
        D (row = 1,column = 1,PADX = 5,pady = 5) self.button1.bind ("<ButtonRelease-1>", Self.buttonlistener1) Self.button2.bind ("<ButtonRelease-1>", Self.buttonlistener2) self.button3.bind ("<ButtonRelease-1>", SELF.BUTTONLISTENER3) Self.button4.bind ("<ButtonRelease-1>", Self.buttonlistener4) Self.frame.mainlo OP () window = MainWindow ()

The results of a graphical interface (which is notable for self) are shown in the way that the class is defined to run as follows:

Python3 Module Change Address reference:

Http://docs.pythonsprints.com/python3_porting/py-porting.html

Python control and layout reference address:

Http://effbot.org/tkinterbook/tkinter-index.htm#class-reference

Two examples of graphical interfaces written in Python:

From tkinter Import * class Mainwindow:def __init__ (self): Self.frame = Tk () Self.label_name = Labe L (self.frame,text = "Name:") self.label_age = label (Self.frame,text = "Age:") Self.label_sex = label (self. Frame,text = "Sex:") self.text_name = text (self.frame,height = "1", width =) Self.text_age = text (self. Frame,height = "1", width = Self.text_sex = text (self.frame,height = "1", width =) self.label_name.g

        RID (row = 0,column = 0) self.label_age.grid (row = 1,column = 0) self.label_sex.grid (row = 2,column = 0) SELF.BUTTON_OK = button (Self.frame,text = "OK", Width = ten) Self.button_cancel = button (Self.frame,text = "C
        Ancel ", width = ten" self.text_name.grid (row = 0,column = 1) self.text_age.grid (row = 1,column = 1) Self.text_sex.grid (row = 2,column = 1) self.button_ok.grid (row = 3,column = 0) self.button_cance L.grid (row = 3,column =1) self.frame.mainloop () frame = MainWindow () 
Run Result:



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.