python计算器gui设计_python pyQT新手问题:制作简易计算器GUI: 已经完成cal.ui和.py,求助各位大哥怎么将另一个类写进面板?...

另一个.py文件中的:

import sys

import string

from PyQt4 import QtCore, QtGui

from calculator import Ui_Form#这条语句就是导入要引用的界面文件的python文件

class MyForm(QtGui.QMainWindow):

def __init__(self, parent=None):

#定义全局变量

self.str1 = ''#接收第一个要运算的数

self.str2 = ''#接收第二个要运算的数

self.flag = '0'

self.calFlag = ''

QtGui.QWidget.__init__(self, parent)

self.ui = Ui_Form()

self.ui.setupUi(self)

self.ui.display.setText(self.str1)

#菜单的设置

exit = QtGui.QAction(QtGui.QIcon('icons/exit.png'), 'Exit', self)

exit.setShortcut('Ctrl+Q')

self.connect(exit, QtCore.SIGNAL('triggered()'), QtCore.SLOT('close()'))

menubar = self.menuBar()

file = menubar.addMenu('&File')

file.addAction(exit)

#数字键事件处理

QtCore.QObject.connect(self.ui.button_7,QtCore.SIGNAL("clicked()"),self.func_button7)

QtCore.QObject.connect(self.ui.button_8,QtCore.SIGNAL("clicked()"),self.func_button8)

def func_buttonEqual(self):

#字符串先转换为数字,计算结果后再转换为字符串

if self.calFlag == '1':

num = str(int(self.str1) + int(self.str2))

elif self.calFlag == '2':

num = str(int(self.str1) - int(self.str2))

elif self.calFlag == '3':

num = str(int(self.str1) * int(self.str2))

elif self.calFlag == '4':

num = str(int(self.str1) / int(self.str2))

else:

self.calFlag = '0'

self.ui.display.setText(num)

def func_buttonClear(self):

self.str1 = ''

self.str2 = ''

self.ui.display.setText('')

self.flag = '0'

if __name__ == "__main__":

app = QtGui.QApplication(sys.argv)

myapp = MyForm()

myapp.show()

sys.exit(app.exec_())

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值