-
반응형
#import Tkinter toolkit#
from tkinter import*
#key press function:
def click1():
num=1
entry.insert(END,num)
def click2():
num=2
entry.insert(END,num)
def click3():
num=1
entry.insert(END,num)
def click4():
num='+'
entry.insert(END,num)
def click5():
num=4
entry.insert(END,num)
def click6():
num=5
entry.insert(END,num)
def click7():
num=6
entry.insert(END,num)
def click8():
num='-'
entry.insert(END,num)
def click9():
num=7
entry.insert(END,num)
def click10():
num=8
entry.insert(END,num)
def click11():
num=9
entry.insert(END,num)
def click12():
num='*'
entry.insert(END,num)
def click13():
entry.delete(0,END)
def click14():
num=0
entry.insert(END,num)
def click15():
output=entry.get()
numsum=str(eval(output))
entry.delete(0,END)
entry.insert(END,numsum)
def click16():
num='/'
entry.insert(END,num)
# main:#
window = Tk()
#Run mainloop#
window.title("Calculator")
#create text entry box
entry=Entry(window,width=20,bg="yellow")
entry.grid(row=0,column=0,columnspan=4,sticky=W)
Button(window,text="1",width=5,command=click1).grid(row=1,column=0,sticky=W)
Button(window,text="2",width=5,command=click2).grid(row=1,column=1,sticky=W)
Button(window,text="3",width=5,command=click3).grid(row=1,column=2,sticky=W)
Button(window,text="+",width=5,command=click4).grid(row=1,column=3,sticky=W)
Button(window,text="4",width=5,command=click5).grid(row=2,column=0,sticky=W)
Button(window,text="5",width=5,command=click6).grid(row=2,column=1,sticky=W)
Button(window,text="6",width=5,command=click7).grid(row=2,column=2,sticky=W)
Button(window,text="-",width=5,command=click8).grid(row=2,column=3,sticky=W)
Button(window,text="7",width=5,command=click9).grid(row=3,column=0,sticky=W)
Button(window,text="8",width=5,command=click10).grid(row=3,column=1,sticky=W)
Button(window,text="9",width=5,command=click11).grid(row=3,column=2,sticky=W)
Button(window,text="*",width=5,command=click12).grid(row=3,column=3,sticky=W)
Button(window,text="c",width=5,command=click13).grid(row=4,column=0,sticky=W)
Button(window,text="0",width=5,command=click14).grid(row=4,column=1,sticky=W)
Button(window,text="=",width=5,command=click15).grid(row=4,column=2,sticky=W)
Button(window,text="/",width=5,command=click16).grid(row=4,column=3,sticky=W)
window.mainloop()
반응형'Python' 카테고리의 다른 글
windows에서 virtualenv 이용시 패키지 설치 방법 (1) 2020.08.20 파이썬 - 정규식 (0) 2019.10.24 Python으로 Selenium 이용 시 Element Check (0) 2019.04.15 파이썬3 피라미드 (0) 2017.12.25 파이썬 아나콘다 Python3, Python2 동시 설치(다중커널 설치) (0) 2017.09.28 댓글