本文实例为大家分享了wxPython实现计算器的具体代码,供大家参考,具体内容如下
# -*- coding: utf-8 -*- ########################################## ## Python code generated with wxFormBuilder (version Feb 16 2016) ## http://www.wxformbuilder.org/ ## ## PLEASE DO "NOT" EDIT THIS FILE! ########################################## import wx import wx.xrc import math ############################################# ## Class MyFrame1 ############################################# class MyFrame1(wx.Frame): def __init__(self, parent): wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=wx.EmptyString, pos=wx.DefaultPosition, size=wx.Size(486, 448), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL) self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize) bSizer1 = wx.BoxSizer(wx.VERTICAL) self.m_textCtrl1 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.Size(600, 60), style=wx.TE_RIGHT) self.m_textCtrl1.SetMinSize(wx.Size(470, 60)) bSizer1.Add(self.m_textCtrl1, 0, wx.ALL, 5) bSizer2 = wx.BoxSizer(wx.HORIZONTAL) self.m_button1 = wx.Button(self, wx.ID_ANY, u"退格", wx.DefaultPosition, wx.Size(110, 60), 0) bSizer2.Add(self.m_button1, 0, wx.ALL, 5) self.m_button2 = wx.Button(self, wx.ID_ANY, u"清屏", wx.DefaultPosition, wx.Size(110, 60), 0) bSizer2.Add(self.m_button2, 0, wx.ALL, 5) self.m_button3 = wx.Button(self, wx.ID_ANY, u"sqrt", wx.DefaultPosition, wx.Size(110, 60), 0) bSizer2.Add(self.m_button3, 0, wx.ALL, 5) self.m_button4 = wx.Button(self, wx.ID_ANY, u"/", wx.DefaultPosition, wx.Size(110, 60), 0) bSizer2.Add(self.m_button4, 0, wx.ALL, 5) bSizer1.Add(bSizer2, 0, wx.EXPAND, 5) bSizer6 = wx.BoxSizer(wx.HORIZONTAL) self.m_button10 = wx.Button(self, wx.ID_ANY, u"7", wx.DefaultPosition, wx.Size(110, 60), 0) bSizer6.Add(self.m_button10, 0, wx.ALL, 5) self.m_button11 = wx.Button(self, wx.ID_ANY, u"8", wx.DefaultPosition, wx.Size(110, 60), 0) bSizer6.Add(self.m_button11, 0, wx.ALL, 5) self.m_button12 = wx.Button(self, wx.ID_ANY, u"9", wx.DefaultPosition, wx.Size(110, 60), 0) bSizer6.Add(self.m_button12, 0, wx.ALL, 5) self.m_button13 = wx.Button(self, wx.ID_ANY, u"*", wx.DefaultPosition, wx.Size(110, 60), 0) bSizer6.Add(self.m_button13, 0, wx.ALL, 5) bSizer1.Add(bSizer6, 0, wx.EXPAND, 5) bSizer7 = wx.BoxSizer(wx.HORIZONTAL) self.m_button15 = wx.Button(self, wx.ID_ANY, u"4", wx.DefaultPosition, wx.Size(110, 60), 0) bSizer7.Add(self.m_button15, 0, wx.ALL, 5) self.m_button16 = wx.Button(self, wx.ID_ANY, u"5", wx.DefaultPosition, wx.Size(110, 60), 0) bSizer7.Add(self.m_button16, 0, wx.ALL, 5) self.m_button17 = wx.Button(self, wx.ID_ANY, u"6", wx.DefaultPosition, wx.Size(110, 60), 0) bSizer7.Add(self.m_button17, 0, wx.ALL, 5) self.m_button18 = wx.Button(self, wx.ID_ANY, u"-", wx.DefaultPosition, wx.Size(110, 60), 0) bSizer7.Add(self.m_button18, 0, wx.ALL, 5) bSizer1.Add(bSizer7, 0, wx.EXPAND, 5) bSizer34 = wx.BoxSizer(wx.HORIZONTAL) self.m_button140 = wx.Button(self, wx.ID_ANY, u"1", wx.DefaultPosition, wx.Size(110, 60), 0) bSizer34.Add(self.m_button140, 0, wx.ALL, 5) self.m_button141 = wx.Button(self, wx.ID_ANY, u"2", wx.DefaultPosition, wx.Size(110, 60), 0) bSizer34.Add(self.m_button141, 0, wx.ALL, 5) self.m_button142 = wx.Button(self, wx.ID_ANY, u"3", wx.DefaultPosition, wx.Size(110, 60), 0) bSizer34.Add(self.m_button142, 0, wx.ALL, 5) self.m_button143 = wx.Button(self, wx.ID_ANY, u"+", wx.DefaultPosition, wx.Size(110, 60), 0) bSizer34.Add(self.m_button143, 0, wx.ALL, 5) bSizer1.Add(bSizer34, 0, wx.EXPAND, 5) bSizer35 = wx.BoxSizer(wx.HORIZONTAL) self.m_button145 = wx.Button(self, wx.ID_ANY, u"0", wx.DefaultPosition, wx.Size(110, 60), 0) bSizer35.Add(self.m_button145, 0, wx.ALL, 5) self.m_button148 = wx.Button(self, wx.ID_ANY, u".", wx.DefaultPosition, wx.Size(110, 60), 0) bSizer35.Add(self.m_button148, 0, wx.ALL, 5) self.m_button149 = wx.Button(self, wx.ID_ANY, u"+/-", wx.DefaultPosition, wx.Size(110, 60), 0) bSizer35.Add(self.m_button149, 0, wx.ALL, 5) self.m_button150 = wx.Button(self, wx.ID_ANY, u"=", wx.DefaultPosition, wx.Size(110, 600), 0) self.m_button150.SetMinSize(wx.Size(110, 60)) bSizer35.Add(self.m_button150, 0, wx.ALL, 5) bSizer1.Add(bSizer35, 0, wx.EXPAND, 5) self.SetSizer(bSizer1) self.Layout() self.Centre(wx.BOTH) # Connect Events self.m_button1.Bind(wx.EVT_BUTTON, self.m_button1OnButtonClick) self.m_button2.Bind(wx.EVT_BUTTON, self.m_button2OnButtonClick) self.m_button3.Bind(wx.EVT_BUTTON, self.m_button3OnButtonClick) self.m_button4.Bind(wx.EVT_BUTTON, self.m_button4OnButtonClick) self.m_button10.Bind(wx.EVT_BUTTON, self.m_button10OnButtonClick) self.m_button11.Bind(wx.EVT_BUTTON, self.m_button11OnButtonClick) self.m_button12.Bind(wx.EVT_BUTTON, self.m_button12OnButtonClick) self.m_button13.Bind(wx.EVT_BUTTON, self.m_button13OnButtonClick) self.m_button15.Bind(wx.EVT_BUTTON, self.m_button15OnButtonClick) self.m_button16.Bind(wx.EVT_BUTTON, self.m_button16OnButtonClick) self.m_button17.Bind(wx.EVT_BUTTON, self.m_button17OnButtonClick) self.m_button18.Bind(wx.EVT_BUTTON, self.m_button18OnButtonClick) self.m_button140.Bind(wx.EVT_BUTTON, self.m_button140OnButtonClick) self.m_button141.Bind(wx.EVT_BUTTON, self.m_button141OnButtonClick) self.m_button142.Bind(wx.EVT_BUTTON, self.m_button142OnButtonClick) self.m_button143.Bind(wx.EVT_BUTTON, self.m_button143OnButtonClick) self.m_button145.Bind(wx.EVT_BUTTON, self.m_button145OnButtonClick) self.m_button148.Bind(wx.EVT_BUTTON, self.m_button148OnButtonClick) self.m_button149.Bind(wx.EVT_BUTTON, self.m_button149OnButtonClick) self.m_button150.Bind(wx.EVT_BUTTON, self.m_button150OnButtonClick) def __del__(self): pass # Virtual event handlers, overide them in your derived class def m_button1OnButtonClick(self, event): result=self.m_textCtrl1.GetValue() result=result[:-1] self.m_textCtrl1.SetValue(result) def m_button2OnButtonClick(self, event): result=self.m_textCtrl1.GetValue() result='' self.m_textCtrl1.SetValue(result) def m_button3OnButtonClick(self, event): result=self.m_textCtrl1.GetValue() result=int(result) result=math.sqrt(result) self.m_textCtrl1.SetValue(str(result)) def m_button4OnButtonClick(self, event): result=self.m_textCtrl1.GetValue() result=result+'/' self.m_textCtrl1.SetValue(result) def m_button10OnButtonClick(self, event): result=self.m_textCtrl1.GetValue() result=result+'7' self.m_textCtrl1.SetValue(result) def m_button11OnButtonClick(self, event): result=self.m_textCtrl1.GetValue() result=result+'8' self.m_textCtrl1.SetValue(result) def m_button12OnButtonClick(self, event): result=self.m_textCtrl1.GetValue() result=result+'9' self.m_textCtrl1.SetValue(result) def m_button13OnButtonClick(self, event): result=self.m_textCtrl1.GetValue() result=result+'*' self.m_textCtrl1.SetValue(result) def m_button15OnButtonClick(self, event): result=self.m_textCtrl1.GetValue() result=result+'4' self.m_textCtrl1.SetValue(result) def m_button16OnButtonClick(self, event): result=self.m_textCtrl1.GetValue() result=result+'5' self.m_textCtrl1.SetValue(result) def m_button17OnButtonClick(self, event): result=self.m_textCtrl1.GetValue() result=result+'6' self.m_textCtrl1.SetValue(result) def m_button18OnButtonClick(self, event): result=self.m_textCtrl1.GetValue() result=result+'-' self.m_textCtrl1.SetValue(result) def m_button140OnButtonClick(self, event): result=self.m_textCtrl1.GetValue() result=result+'1' self.m_textCtrl1.SetValue(result) def m_button141OnButtonClick(self, event): result=self.m_textCtrl1.GetValue() result=result+'2' self.m_textCtrl1.SetValue(result) def m_button142OnButtonClick(self, event): result=self.m_textCtrl1.GetValue() result=result+'3' self.m_textCtrl1.SetValue(result) def m_button143OnButtonClick(self, event): result=self.m_textCtrl1.GetValue() result=result+'+' self.m_textCtrl1.SetValue(result) def m_button145OnButtonClick(self, event): result=self.m_textCtrl1.GetValue() result=result+'0' self.m_textCtrl1.SetValue(result) def m_button148OnButtonClick(self, event): result=self.m_textCtrl1.GetValue() result=result+'.' self.m_textCtrl1.SetValue(result) def m_button149OnButtonClick(self, event): result=self.m_textCtrl1.GetValue() result=-int(result) self.m_textCtrl1.SetValue(str(result)) def m_button150OnButtonClick(self, event): self.m_textCtrl1.SetValue(str(eval(self.m_textCtrl1.GetValue()))) app=wx.App() window=MyFrame1(None) window.Show(True) app.MainLoop()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“Python使用wxPython实现计算器”评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新动态
2024年11月26日
2024年11月26日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]