我仍在学习 Python 和 PyQt4,当按下“Harvest”按钮时,我似乎无法在我的 gui 窗口上显示任何内容。我用粗体强调了我对信号和插槽的了解不足。
更新代码:
import sys, random, sqlite3, os
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtGui, QtCore
from geodesic import Ui_MainWindow
class gameWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(gameWindow, self).__init__(parent)
QtGui.QMainWindow.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
buttonHarvest = QPushButton("Harvest") #Create the harvest button - but QT Designer made it?
buttonMining = QPushButton("Mining") # Create the mining button - but QT Designer made it?
self.label = QLabel("Example") # Set the empty label that's not showing
self.connect(buttonHarvest, SIGNAL("clicked()"), self.skillHarvest) #Gets from def skillHarvest
self.setWindowTitle("Geodesic")
# Next -------------------------------------------------------------------------------------
self.connect(buttonMining, SIGNAL("clicked()"), self.skillMining) #Gets from def skillMining
def skillHarvest(self):
harvest = "You find some roots."
self.label.setText(harvest)
def skillMining(self):
mining = "You found some gold."
self.label.setText(mining)
app = QApplication(sys.argv)
showWindow = gameWindow()
showWindow.show()
app.exec_()