是否有可能讓我得到pyqt信號觸發另一個類的方法? 我嘗試了各種各樣,但沒有運氣。 我的目標是在單擊room_file_button(標記)時觸發get_rooms中的pickFile()方法。連接pyqt信號與另一個類
import sys
from PyQt4 import QtCore, QtGui, uic
import openpyxl
from openpyxl import load_workbook
from openpyxl.styles import Protection
import xlrd
import csv
import os
import re
class MyApp(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
self.room_file_button.clicked.connect(get_rooms.pickFile) # this one
self.radioButton_1.clicked.connect(self.onRadioButton1)
self.radioButton_2.clicked.connect(self.onRadioButton2)
self.radioButton_3.clicked.connect(self.onRadioButton3)
self.spinBox.valueChanged.connect(self.valuechange)
class first_file(MyApp):
def __init__(self):
MyApp.__init__(self)
some methods ....
class get_rooms(MyApp):
def __init__(self):
MyApp.__init__(self)
def pickFile(self, value, group_1):
print 'yipeee !'
xy = 0
while True:
filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '.')
if filename == '' and xy < 2:
print(" ")
xy = xy + 1
continue
elif filename != '':
break
else:
sys.exit()
爲什麼是類'first_file'和'get_rooms'從'MyApp'繼承?你想達到什麼目的?請多給點信息。 – DreyFax