最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

今天把好丑的計(jì)算器源碼給你了!

2020-04-27 16:05 作者:1048576_  | 我要投稿

from tkinter import *
from easygui import msgbox
w = Tk()
num1, num2 = IntVar(), IntVar()
flag, equation = StringVar(),StringVar()
def num(n):
? ?global num1,num2
? ?if flag != '':
? ? ? ?num1.set(num1.get()*10+n)
? ?else:
? ? ? ?num2.set(num2.get()*10+n)
? ?equation.set(equation.get() + str(n))
def set_flag(fl):
? ?flag.set(fl)
? ?equation.set(equation.get() + str(fl))
def calculate():
? ?try:
? ? ? ?msgbox(eval(equation.get().replace('×','*').replace('÷','/').replace('^','**')))
? ?except Exception as e:
? ? ? ?msgbox('出現(xiàn)錯誤:'+str(e))
? ?equation.set('')
w.geometry('1000x1000+200+200')
Button(w, text=0, command=lambda: num(0), width=7, height=3, font=('Arial',20)).grid(row=1,column=0)
Button(w, text=1, command=lambda: num(1), width=7, height=3, font=('Arial',20)).grid(row=1,column=1)
Button(w, text=2, command=lambda: num(2), width=7, height=3, font=('Arial',20)).grid(row=1,column=2)
Button(w, text=3, command=lambda: num(3), width=7, height=3, font=('Arial',20)).grid(row=2,column=0)
Button(w, text=4, command=lambda: num(4), width=7, height=3, font=('Arial',20)).grid(row=2,column=1)
Button(w, text=5, command=lambda: num(5), width=7, height=3, font=('Arial',20)).grid(row=2,column=2)
Button(w, text=6, command=lambda: num(6), width=7, height=3, font=('Arial',20)).grid(row=3,column=0)
Button(w, text=7, command=lambda: num(7), width=7, height=3, font=('Arial',20)).grid(row=3,column=1)
Button(w, text=8, command=lambda: num(8), width=7, height=3, font=('Arial',20)).grid(row=3,column=2)
Button(w, text=9, command=lambda: num(9), width=7, height=3, font=('Arial',20)).grid(row=4,column=1)
Button(w, text='+', command=lambda: set_flag('+'), width=7, height=3, font=('Arial',20)).grid(row=1, column=3)
Button(w, text='-', command=lambda: set_flag('-'), width=7, height=3, font=('Arial',20)).grid(row=2, column=3)
Button(w, text='×', command=lambda: set_flag('×'), width=7, height=3, font=('Arial',20)).grid(row=3, column=3)
Button(w, text='÷', command=lambda: set_flag('÷'), width=7, height=3, font=('Arial',20)).grid(row=4, column=3)
Button(w, text='^', command=lambda: set_flag('^'), width=7, height=3, font=('Arial',20)).grid(row=4, column=2)
Button(w, text='=', command=calculate, width=7, height=3, font=('Arial',20)).grid(row=4,column=0)
Label(w, textvar=equation, font=('Arial',30)).grid(row=0,column=1)
w.title('計(jì)算器')
w.mainloop()

今天把好丑的計(jì)算器源碼給你了!的評論 (共 條)

分享到微博請遵守國家法律
德庆县| 新安县| 普宁市| 孝昌县| 林州市| 舞阳县| 桦川县| 靖江市| 桐城市| 大安市| 娱乐| 西昌市| 图木舒克市| 资源县| 宣汉县| 武冈市| 大丰市| 津南区| 牟定县| 临颍县| 西乡县| 高青县| 海城市| 咸阳市| 沈丘县| 包头市| 陇西县| 滨州市| 丰宁| 南澳县| 尼勒克县| 新邵县| 清镇市| 乌兰浩特市| 墨玉县| 台山市| 拜城县| 辽源市| 连州市| 德庆县| 沾化县|