Python Gadget-Alert bullet box output name age, sum

Source: Internet
Author: User

Use the Python-Tkinter library for GUI programming and complete two functions:

(1) Ask the user to enter a name and age and print it out

(2) Require the user to enter a number and then calculate 1 to the number of the and

Code section:

# Import all the contents of Tkinter in all packages fromTkinter Import *Import Tkinter.messagebox asmessagebox# derives from frame a application class, which is the parent container for all widgetsclassApplication (Frame): def __init__ (Self,master=None): frame.__init__ (Self,master) Self.pack () self.createwidgets () def createwidgets (self): # module 1, set user input one character, alert bullet box output Hello+the character Self.hellolabel= Label (self, text='Module 1: Please enter your name and age, the program will be printed out'The self.helloLabel.pack () # Pack () method adds widgets to the parent container and implements the layout. Self.nameinput=Entry (self) self.nameInput.pack () Self.ageinput=Entry (self) self.ageInput.pack () Self.alertbutton= Button (self,text='Submit', command=Self.hello) Self.alertButton.pack () # module 2, set the user to enter a number, the Alert bullet box calculates the multiple of the number Self.hellolabel= Label (self, text='Module 2: Entering any number will calculate 1 to the number and the'The self.helloLabel.pack () # Pack () method adds widgets to the parent container and implements the layout. Self.numberinput=Entry (self) self.numberInput.pack () Self.alertbutton= Button (self,text='Submit', command=self.sum) Self.alertButton.pack () # Exit button settings Self.quitbutton= Button (self, text='Exit', command=self.quit) self.quitButton.pack () def hello (self): name= Self.nameinput.Get() or' World'# Get user-entered content age= Self.ageinput.Get() or -Messagebox.showinfo ('Personal Information','Name:%s\n Age:%s Years'%(name,age) # Call user input and print out def sum (self): number=int(Self.numberinput.Get()) # Gets the content entered by the user sum=0         forIinchRange (number): I+=1sum+=I messagebox.showinfo ('sum result','1 to%s and%s'% (number,sum) # calls the user input (number *2) and print it out # Instantiate app=application () # set window title: App.master.title ('Hello World') # main message loop App.mainloop ()

Execution effect:

Python Gadget-Alert bullet box output name age, sum

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.