PyQt5 – 单击时隐藏按钮
在本文中,我们将看到如何隐藏按钮。当我们设计一个 GUI(图形用户界面)时,我们会在其中创建按钮,当它们被按下时会执行一些任务。但有时他们需要在任务完成时隐藏按钮,为了隐藏按钮,我们将使用 hide 方法。
Syntax : button.hide()
Argument : It takes no argument.
Action performed : It hides the push button
代码 :
Python3
# importing libraries
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys
class Window(QMainWindow):
def __init__(self):
super().__init__()
# setting title
self.setWindowTitle("Python ")
# setting geometry
self.setGeometry(100, 100, 600, 400)
# creating a button
self.button = QPushButton("CLICK", self)
# setting up the geometry
self.button.setGeometry(200, 150, 200, 40)
# connecting method when button get clicked
self.button.clicked.connect(self.clickme)
# showing all the widgets
self.show()
# action method
def clickme(self):
# hiding the button
self.button.hide()
# printing pressed
print("pressed")
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app
sys.exit(App.exec())
输出 :
按下单击按钮时,将生成输出并且按钮将被隐藏。
pressed