Hello to the Python starter case

Source: Internet
Author: User

 fromTkinterImport* class application(Frame):     def Say_hi(self):        Print ' Hello '     def createwiegets(self):Self. QUIT = Button (self) self. quit["Text"] ="QUIT"Self. quit["FG"] ="Red"Self. quit["command"] = Self.quit self. Quit.pack ({"Side":"left"}) Self.hi_there = Button (self) self.hi_there["Text"] ="Hello"self.hi_there["command"] = Self.say_hi Self.hi_there.pack ({"Side":"left"}) def __init__(self,master=none):frame.__init__ (Self,master) Self.pack () self.createwiegets () root = Tk () app = Application (master = root) app.m Ainloop () Root.destroy ()

This code shows how to use Python to create a graphical interface. Using the Tkinter in Python is a library of graphical interfaces.

    • Import the appropriate module:from Tkinter import *
    • Define a class that inherits a frame
 class application(Frame):     def Say_hi(self):        Print ' Hello '     def createwiegets(self):Self. QUIT = Button (self) self. quit["Text"] ="QUIT"Self. quit["FG"] ="Red"Self. quit["command"] = Self.quit self. Quit.pack ({"Side":"left"}) Self.hi_there = Button (self) self.hi_there["Text"] ="Hello"self.hi_there["command"] = Self.say_hi Self.hi_there.pack ({"Side":"left"}) def __init__(self,master=none):frame.__init__ (Self,master) Self.pack () self.createwiegets ()
    • Defining controls
 def Createwiegets ( Self):         Self.QUIT=Button( Self) Self.QUIT["Text"] ="QUIT"         Self.QUIT["FG"] ="Red"         Self.QUIT["command"] = Self. Quit Self.QUIT. Pack ({"Side":"left" }) Self. Hi_there =Button( Self) Self. hi_there["Text"] ="Hello"         Self. hi_there["command"] = Self. Say_hi Self. Hi_there.pack ({"Side":"left" })
    • Create an object and use
root = Tk()app = Application(master = root)app.mainloop()root.destroy()

In the code snippet above, root is the container for the window, we create the Application object and specify its window container, turn on the message queue loop, and finally destroy the window.

Hello to the Python starter case

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.