![](/img/trans.png)
[英]How do I get the contents of a row of QTableWidget with click on the button in python and PyQt
[英]How to replace the contents in a frame on button click in Pyqt
所以我有兩個框架,第一個框架包含所有標題元素,第二個框架包含具有兩個按鈕的圖像。這是我的第一個屏幕的內容。 現在,當我單擊按鈕時,第二幀中的內容應替換為具有屬性列表的.py文件。第一幀的內容在所有屏幕上都相同,僅第二幀應更改。是我在第一個屏幕上看到的代碼:
import sys
import os
import taurus
from PyQt4 import QtCore, QtGui, uic
from taurus.external.qt import Qt
from taurus.qt.qtgui.panel import TaurusForm
from taurus.qt.qtgui.application import TaurusApplication
form_class = uic.loadUiType("FirstScreen.ui")[0] # Load the UI
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class MyWindowClass(QtGui.QMainWindow, form_class):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.setupUi(self)
#self.editValue.clicked.connect(self.openForm_clicked)
self.setWindowTitle('FirstScreen')
self.button1.setStyleSheet("QPushButton { background-color:#00FFFF;}")
self.dateTime.setText(QtCore.QDate.currentDate().toString())
self.timeLabel.setText(QtCore.QTime.currentTime().toString())
self.button2.setStyleSheet("QPushButton { background-color:#00FFFF;}")
myPixmap = QtGui.QPixmap(_fromUtf8('Sample.png'))
myPixmap=myPixmap.scaledToHeight(100)
self.pic.setPixmap(myPixmap)
app = QtGui.QApplication(sys.argv)
myWindow = MyWindowClass(None)
myWindow.show()
app.exec_()
您能否讓我知道如何在單擊按鈕時使用.py文件加載第二幀。 我嘗試加載的其他.py文件也是使用Pyqt創建的。
您可以使用信號和插槽 。 即使用點擊信號並調用一個函數,例如:onClick。
self.button_name.clicked.connect(self.onClick)
在函數調用中
self.second_frame = second_ui_class()
self.second_frame.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.