内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

怎么在python中使用tkinter實(shí)現(xiàn)一個(gè)計(jì)算器-創(chuàng)新互聯(lián)

怎么在python中使用tkinter實(shí)現(xiàn)一個(gè)計(jì)算器?相信很多沒(méi)有經(jīng)驗(yàn)的人對(duì)此束手無(wú)策,為此本文總結(jié)了問(wèn)題出現(xiàn)的原因和解決方法,通過(guò)這篇文章希望你能解決這個(gè)問(wèn)題。

創(chuàng)新互聯(lián)建站自成立以來(lái),一直致力于為企業(yè)提供從網(wǎng)站策劃、網(wǎng)站設(shè)計(jì)、成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)、電子商務(wù)、網(wǎng)站推廣、網(wǎng)站優(yōu)化到為企業(yè)提供個(gè)性化軟件開(kāi)發(fā)等基于互聯(lián)網(wǎng)的全面整合營(yíng)銷服務(wù)。公司擁有豐富的網(wǎng)站建設(shè)和互聯(lián)網(wǎng)應(yīng)用系統(tǒng)開(kāi)發(fā)管理經(jīng)驗(yàn)、成熟的應(yīng)用系統(tǒng)解決方案、優(yōu)秀的網(wǎng)站開(kāi)發(fā)工程師團(tuán)隊(duì)及專業(yè)的網(wǎng)站設(shè)計(jì)師團(tuán)隊(duì)。

具體內(nèi)容如下

class Counter: 
 #引入tkinter 
 import tkinter as tk 
 #引入消息彈窗模塊 
 import tkinter.messagebox as mbox 
 
 #初始化Counter 
 def __init__(self): 
 #生成一個(gè)窗口對(duì)象 
 self.window = self.tk.Tk() 
 #命名窗口對(duì)象的顯示title 
 self.window.title('計(jì)算器') 
 #設(shè)置窗口的大小 
 self.window.minsize(240, 325) 
 self.window.maxsize(240, 325) 
 #是否清空顯示框判定參數(shù) 
 self.is_init_lable = False 
 #設(shè)置菜單 
 self.set_menu() 
 #設(shè)置顯示框 
 self.lable_show = self.tk.Label(text='', anchor='se', font=('黑體', 30), fg='black') 
 self.lable_show.place(x=0, y=0, width=240, height=80) 
 #設(shè)置按鈕組件 
 self.set_buttons() 
 #將窗口放入主消息隊(duì)列 
 self.window.mainloop() 
 
 #設(shè)置菜單 
 def set_menu(self): 
 #創(chuàng)建總菜單 
 menubar = self.tk.Menu(self.window) 
 #創(chuàng)建一個(gè)下拉菜單,并且加入文件菜單 
 filemenu = self.tk.Menu(menubar, tearoff=0) 
 #創(chuàng)建下來(lái)菜單的選項(xiàng) 
 filemenu.add_command(label="退出計(jì)算器", command=self.window.quit) 
 #print author的函數(shù) 
 def show_author(): 
  self.mbox.showinfo(message='Wiz333@XDL 2017') 
 filemenu.add_command(label="作者", command=show_author) 
 #將文件菜單作為下拉菜單添加到總菜單中,并且將命名為操作 
 menubar.add_cascade(label="操作", menu=filemenu) 
 #顯示總菜單 
 self.window.config(menu=menubar) 
 
 #設(shè)置按鈕組件 
 def set_buttons(self): 
 #7 
 btn7 = self.tk.Button(text='7', bd=2, font='黑體') 
 btn7.place(x=0, y=90, width=60, height=40) 
 #8 
 btn8 = self.tk.Button(text='8', bd=2, font='黑體') 
 btn8.place(x=60, y=90, width=60, height=40) 
 #9 
 btn9 = self.tk.Button(text='9', bd=2, font='黑體') 
 btn9.place(x=120, y=90, width=60, height=40) 
 #+ 
 btn_jia = self.tk.Button(text='+', bd=2, font='黑體') 
 btn_jia.place(x=180, y=90, width=60, height=40) 
 #4 
 btn4 = self.tk.Button(text='4', bd=2, font='黑體') 
 btn4.place(x=0, y=130, width=60, height=40) 
 #5 
 btn5 = self.tk.Button(text='5', bd=2, font='黑體') 
 btn5.place(x=60, y=130, width=60, height=40) 
 #6 
 btn6 = self.tk.Button(text='6', bd=2, font='黑體') 
 btn6.place(x=120, y=130, width=60, height=40) 
 #- 
 btn_jian = self.tk.Button(text='-', bd=2, font='黑體') 
 btn_jian.place(x=180, y=130, width=60, height=40) 
 #1 
 btn1 = self.tk.Button(text='1', bd=2, font='黑體') 
 btn1.place(x=0, y=170, width=60, height=40) 
 #2 
 btn2 = self.tk.Button(text='2', bd=2, font='黑體') 
 btn2.place(x=60, y=170, width=60, height=40) 
 #3 
 btn3 = self.tk.Button(text='3', bd=2, font='黑體') 
 btn3.place(x=120, y=170, width=60, height=40) 
 #* 
 btn_cheng = self.tk.Button(text='*', bd=2, font='黑體') 
 btn_cheng.place(x=180, y=170, width=60, height=40) 
 #0 
 btn0 = self.tk.Button(text='0', bd=2, font='黑體') 
 btn0.place(x=0, y=210, width=120, height=40) 
 #. 
 btn_point = self.tk.Button(text='.', bd=2, font='黑體') 
 btn_point.place(x=120, y=210, width=60, height=40) 
 #/ 
 btn_chu = self.tk.Button(text='/', bd=2, font='黑體') 
 btn_chu.place(x=180, y=210, width=60, height=40) 
 #取消 
 btn_cancel = self.tk.Button(text='C', bd=2, font='黑體') 
 btn_cancel.place(x=0, y=250, width=60, height=40) 
 #確定 
 btn_ok = self.tk.Button(text='=', bd=2, font='黑體') 
 btn_ok.place(x=60, y=250, width=180, height=40) 
 #綁定Button的點(diǎn)擊事件 
 btn7.bind_class('Button', '<Button-1>', self.click_button) 
 
 #綁定Button的點(diǎn)擊事件 
 def click_button(self,e): 
 #判斷是否是新的運(yùn)算,如果是則清空顯示框 
 if self.is_init_lable: 
  self.lable_show['text'] = '' 
  self.is_init_lable = False 
 #label_show顯示的累加 
 font = e.widget['text'] 
 self.lable_show['text'] += font 
 #異常捕獲 
 try: 
  #判定運(yùn)算符號(hào)重復(fù)的時(shí)候,使用最后輸入的符號(hào) 
  if self.lable_show['text'][-1] in ['+','-','*','/'] and self.lable_show['text'][-2] in ['+','-','*','/']: 
  header = self.lable_show['text'][:-2] 
  footer = self.lable_show['text'][-1] 
  self.lable_show['text'] = header+footer 
 except: 
  pass 
 
 #普通計(jì)算 
 if e.widget['text'] == '=': 
  try: 
  res = eval(self.lable_show['text'][:-1]) 
  #print(res) 
  #小數(shù)點(diǎn)取到9位 
  self.lable_show['text'] = str(round(float(res), 5)) 
  self.isinit = True 
  except ZeroDivisionError: 
  #除法時(shí),除數(shù)不能為0 
  self.mbox.showerror(message='除法計(jì)算時(shí)!除數(shù)不能為0!') 
  except: 
  self.mbox.showerror(message='算式有誤') 
 #取消當(dāng)前輸入的字符 
 if e.widget['text'] == 'C': 
  cancel_res = self.lable_show['text'][:-2] 
  self.lable_show['text'] = cancel_res 
 
 
#實(shí)例化計(jì)算器對(duì)象 
wiz = Counter()

看完上述內(nèi)容,你們掌握怎么在python中使用tkinter實(shí)現(xiàn)一個(gè)計(jì)算器的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站設(shè)計(jì)公司行業(yè)資訊頻道,感謝各位的閱讀!

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

本文名稱:怎么在python中使用tkinter實(shí)現(xiàn)一個(gè)計(jì)算器-創(chuàng)新互聯(lián)
文章來(lái)源:http://m.rwnh.cn/article42/iiohc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、定制開(kāi)發(fā)Google網(wǎng)站內(nèi)鏈網(wǎng)站設(shè)計(jì)公司、營(yíng)銷型網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站
雅安市| 昭苏县| 辽中县| 屯门区| 嘉义县| 苍梧县| 酒泉市| 滦平县| 盐源县| 和林格尔县| 海淀区| 灵宝市| 玛多县| 望谟县| 崇左市| 赞皇县| 桑日县| 宁安市| 阜新市| 图木舒克市| 双辽市| 临朐县| 云龙县| 正镶白旗| 元阳县| 海淀区| 吴江市| 永平县| 交城县| 边坝县| 鄂温| 福安市| 天门市| 庆云县| 靖安县| 溧水县| 松溪县| 凤山市| 清丰县| 长治市| 柯坪县|