Use Python3 's tkinter to make a simple calculator interface

Source: Internet
Author: User

1#!/usr/bin/python32#-*-coding:utf-8-*-3ImportTkinter4ImportTkinter.font5 6classCalculate ():7def __init__(self):8 self.tk=Tkinter. Tk (); 9 Self.tk.title ("Calculate");1011self.tk.resizable (0,0);Self.showfont=tkinter.font.font (self.tk,size=26);Self.sysfont=tkinter.font.font (self.tk,size=16);1415 Self.entry=tkinter. Entry (Self.tk,width=20,font=self.showfont,bac kground="#ffffff");Self.entry.grid (row=0,column=0,columnspan=4,pady=10);1718 Self.btn1=tkinter. Button (self.tk,text="1", font=Self.sysfont);Self.btn1.grid (Row=1,column=0,sticky=tkinter. N+tkinter. S+tkinter. w+Tkinter. E);2021 Self.btn2=tkinter. Button (self.tk,text="2", font=Self.sysfont);Self.btn2.grid (Row=1,column=1,sticky=tkinter. N+tkinter. S+tkinter. w+Tkinter. E);2324 Self.btn3=tkinter. Button (self.tk,text="3", font=Self.sysfont);Self.btn3.grid (Row=1,column=2,sticky=tkinter. N+tkinter. S+tkinter. w+Tkinter. E);2627 Self.btn_divide=tkinter. Button (self.tk,text="÷", font=Self.sysfon t);Self.btn_divide.grid (Row=1,column=3,sticky=tkinter. N+tkinter. S+t Kinter. w+Tkinter. E);293031 Self.btn4=tkinter. Button (self.tk,text="4", font=Self.sysfont);Self.btn4.grid (Row=2,column=0,sticky=tkinter. N+tkinter. S+tkinter. w+Tkinter. E);3334 Self.btn5=tkinter. Button (self.tk,text="5", font=Self.sysfont);Self.btn5.grid (Row=2,column=1,sticky=tkinter. N+tkinter. S+tkinter. w+Tkinter. E);3637 Self.btn6=tkinter. Button (self.tk,text="6", font=Self.sysfont);Self.btn6.grid (Row=2,column=2,sticky=tkinter. N+tkinter. S+tkinter. w+Tkinter. E);3940 Self.btn_mult=tkinter. Button (self.tk,text="x", font=Self.sysfont);Self.btn_mult.grid (Row=2,column=3,sticky=tkinter. N+tkinter. S+tki nter. w+Tkinter. E);424344 Self.btn7=tkinter. Button (self.tk,text="7", font=Self.sysfont);Self.btn7.grid (Row=3,column=0,sticky=tkinter. N+tkinter. S+tkinter. w+Tkinter. E);4647 Self.btn8=tkinter. Button (self.tk,text="8", font=Self.sysfont);Self.btn8.grid (Row=3,column=1,sticky=tkinter. N+tkinter. S+tkinter. w+Tkinter. E);4950 Self.btn9=tkinter. Button (self.tk,text="9", font=Self.sysfont);Wuyi Self.btn9.grid (Row=3,column=2,sticky=tkinter. N+tkinter. S+tkinter. w+Tkinter. E);5253 Self.btn_minus=tkinter. Button (self.tk,text="-", font=Self.sysfont);Self.btn_minus.grid (Row=3,column=3,sticky=tkinter. N+tkinter. S+TK Inter. w+Tkinter. E);555657 Self.btn0=tkinter. Button (self.tk,text="0", font=Self.sysfont);Self.btn0.grid (Row=4,column=0,sticky=tkinter. N+tkinter. S+tkinter. w+Tkinter. E);5960 Self.btn_point=tkinter. Button (self.tk,text=".", font=Self.sysfont);Self.btn_point.grid (Row=4,column=1,sticky=tkinter. N+tkinter. S+TK Inter. w+Tkinter. E);6263 Self.btn_es=tkinter. Button (self.tk,text="=", font=Self.sysfont);Self.btn_es.grid (Row=4,column=2,sticky=tkinter. N+tkinter. S+tkint er. w+Tkinter. E);6566 Self.btn_add=tkinter. Button (self.tk,text="+", font=Self.sysfont);Self.btn_add.grid (Row=4,column=3,sticky=tkinter. N+tkinter. S+tkin ter. w+Tkinter. E);6869Self.tk.mainloop ();7071 cal=calculate ();

Use Python3 's tkinter to make a simple calculator interface

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.