[PyQt] PyQt4 - Display text on GUI Window:

M.Chavez dunwitch at gmail.com
Sun Oct 25 16:20:53 GMT 2009


I'm trying to get some text to display on the GUI window, I can get it to
print to the console. Here is my sample code, I think I'm close but seem to
be missing something simple. The section in bold is where I'm trying to get
the text to display on the window when the button *pushButtonHarvest* is
pushed.

#!/usr/lib/python
> import sys, random, sqlite3, os
> from PyQt4 import QtGui, QtCore
> from geodesic import Ui_MainWindow
>
> # A new class here
> # derived from QMainWindow
> class TestApp(QtGui.QMainWindow):
>     def __init__(self):
>         QtGui.QMainWindow.__init__(self)
>         self.ui = Ui_MainWindow()
>         self.ui.setupUi(self)
>
> # -- Create the DB connection -- #
> database_name = "rpg.db"
> if not os.path.isfile(database_name):
>     print ("Creating RPG module")
> db_connection = sqlite3.connect(database_name)
> db_cursor = db_connection.cursor()
> try:
>     db_cursor.execute("""CREATE TABLE Skills (id INTEGER PRIMARY KEY
> AUTOINCREMENT, skill TEXT, value TEXT)""")
>     db_cursor.execute ("INSERT INTO Skills (skill, value) VALUES
> ('Harvesting', '0.00')")
>     db_cursor.execute ("INSERT INTO Skills (skill, value) VALUES ('Boyer',
> '0.00')")
>     db_cursor.execute ("INSERT INTO Skills (skill, value) VALUES
> ('Herbalism', '0.00')")
>     db_cursor.execute ("INSERT INTO Skills (skill, value) VALUES ('Mining',
> '0.00')")
>     db_connection.commit()
>     db_connection.close()
> except sqlite3.OperationalError:
>     print ("Connecting to Geodesic.")
>
> # -- Start building the skills -- #
> class Skills:
>     harvest = "Harvesting."
>     boyer = "Boyer."
>     herbalism = "Herbalism."
>     mining = "Mining."
>     def gainMessage(self):
>         return "You have gained"
>     def rollPoint(self):
>         return random.uniform(0.1,0.2)
>
> *class useHarvest(TestApp, Ui_MainWindow, Skills):
>     def __init__(self, text, parent=None):
>         super(useHarvest, self).__init__(parent)
>         useSkill = Skills()
>         self.pushButtonHarvest.setEnabled(enable)
>         self.emit(SIGNAL(useSkill.gainMessage(), ('%.2f' %
> useSkill.rollPoint()), "in", useSkill.harvest))
>         self.ui.setupUi(self)*
>
> if __name__ == "__main__":
>     app = QtGui.QApplication(sys.argv)
>     window = TestApp()
>     window.show()
>     sys.exit(app.exec_())
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20091025/ca3ca9ea/attachment.html


More information about the PyQt mailing list