Hack Forums
[Python] Python calculator - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] Python calculator (/showthread.php?tid=5542206)



Python calculator - Mimzie5 - Feb 3, 2017

I have been learning and coding in python for a while now and i'm having issues with a small project i'm doing (Basic calculator). I cant seem to figure out how to bind the buttons to functions for example i would like to bind button_plus to the addition function i created earlier. Any tips for helping me out?


Also if anyone has any ideas for other projects after i finish this calculator that would be greatly appreciated :)


* - captainspalding - Feb 3, 2017

Going to be pretty difficult to understand what you're talking about without source code. No idea what your functions look like.


* - Infamia - Feb 3, 2017

Pseudo-code:

Code
if button_plus.onPressed:
     addition(x,y)



* - SIM-1866423 - Feb 3, 2017

We got QT.

PHP Code

<?php 
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'untitled.ui'
#
# Created: Sat Feb  4 04:33:54 2017
#      by: PyQt4 UI code generator 4.10.4
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
    
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError
:
    
def _fromUtf8(s):
        return 
s

try:
    
_encoding = QtGui.QApplication.UnicodeUTF8
    def _translate
(context, text, disambig):
        return 
QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    
def _translate(context, text, disambig):
        return 
QtGui.QApplication.translate(context, text, disambig)

class 
Ui_Dialog(object):
    
def setupUi(self, Dialog):
        
Dialog.setObjectName(_fromUtf8("Dialog"))
        
Dialog.resize(356, 135)
        
self.pushButton = QtGui.QPushButton(Dialog)
        
self.pushButton.setGeometry(QtCore.QRect(220, 50, 111, 51))
        
self.pushButton.setObjectName(_fromUtf8("pushButton"))
        
self.lineEdit = QtGui.QLineEdit(Dialog)
        
self.lineEdit.setGeometry(QtCore.QRect(70, 50, 113, 27))
        
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
        
self.lineEdit_2 = QtGui.QLineEdit(Dialog)
        
self.lineEdit_2.setGeometry(QtCore.QRect(70, 80, 113, 27))
        
self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2"))

        
self.retranslateUi(Dialog)
        
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), self.DOSOMETHINGDUDEE)
        
QtCore.QMetaObject.connectSlotsByName(Dialog)

    
def retranslateUi(self, Dialog):
        
Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
        
self.pushButton.setText(_translate("Dialog", "SUM", None))


    
def DOSOMETHINGDUDEE(self):
        print(
"something")


if 
__name__ == "__main__":
    
import sys
    app 
= QtGui.QApplication(sys.argv)
    
Dialog = QtGui.QDialog()
    
ui = Ui_Dialog()
    
ui.setupUi(Dialog)
    
Dialog.show()
    
sys.exit(app.exec_())