使用PyQt5和Qt Designer创建Python GUI应用程序系列(二)
b1 = QtWidgets.QPushButton(win)
b1.setText("点击这里")
#b1.move(100,100) to move the button
def clicked():
print("点击了") # 当按下按钮时,我们将直接打印“点击了”
b1.clicked.connect(clicked) # 内部主要函数
# 注意:函数参数不需要括号(括号中的内容)
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow
import sys
class MyWindow(QMainWindow):
def __init__(self):
super(MyWindow,self).__init__()
self.initUI()
def button_clicked(self):
print("点击了")
def initUI(self):
self.setGeometry(300, 300, 600, 400)
self.setWindowTitle("Linux公社www.linuxidc.com")
self.label = QtWidgets.QLabel(self)
self.label.setText("www.linuxidc.com")
self.label.move(50,50)
self.b1 = QtWidgets.QPushButton(self)
self.b1.setText("点击这里")
self.b1.clicked.connect(self.button_clicked)
def window():
app = QApplication(sys.argv)
win = MyWindow()
win.show()
sys.exit(app.exec_())
window()
def button_clicked(self):
print("点击了")
self.label.setText("你刚才点击了按钮")
class MyWindow(QMainWindow):
...
def clicked_button(self):
self.label.setText("你刚才点击了按钮")
self.update()
...
def update(self):
self.label.adjustSize()
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow
import sys
class MyWindow(QMainWindow):
def __init__(self):
super(MyWindow,self).__init__()
self.initUI()
def button_clicked(self):
self.label.setText("你刚才点击了按钮")
self.update()
def initUI(self):
self.setGeometry(300, 300, 600, 400)
self.setWindowTitle("Linux公社www.linuxidc.com")
self.label = QtWidgets.QLabel(self)
self.label.setText("www.linuxidc.com")
self.label.move(50,50)
self.b1 = QtWidgets.QPushButton(self)
self.b1.setText("点击这里")
self.b1.clicked.connect(self.button_clicked)
def update(self):
self.label.adjustSize()
def window():
app = QApplication(sys.argv)
win = MyWindow()
win.show()
sys.exit(app.exec_())
window()
使用PyQt5和Qt Designer创建Python
GUI应用程序 系列文章总链接见 https://www.linuxidc.com/search.aspx?where=nkey&keyword=65658
本文永久更新链接地址:https://www.linuxidc.com/Linux/2020-05/163132.htm
微信赞赏支付宝赞赏