PyQt5 QSpinBox – 获取系统标识符
在本文中,我们将看到如何获得旋转框的有效窗口系统标识符。有效标识符是指旋转框的原生父窗口系统标识符(ID)。
In order to do this we use effectiveWinId method
Syntax : spin_box.effectiveWinId()
Argument : It takes no argument
Return : If the spin box is native, this function returns the native widget ID. Otherwise, the window ID of the first native parent widget, i.e., the top-level widget that contains this spin box, is returned.
注意:这个方法应该在主窗口打开后调用,即在主窗口类之外
下面是实现
# importing libraries
from PyQt5.QtWidgets import *
from PyQt5 import QtCore, QtGui
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)
# calling method
self.UiComponents()
# showing all the widgets
self.show()
# method for widgets
def UiComponents(self):
# creating spin box
self.spin = QSpinBox(self)
# setting geometry to spin box
self.spin.setGeometry(100, 100, 250, 40)
# setting range to the spin box
self.spin.setRange(0, 999999)
# setting prefix to spin
self.spin.setPrefix("Prefix ")
# setting suffix to spin
self.spin.setSuffix(" Suffix")
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# getting system identifier of spin box
identifier = window.spin.effectiveWinId()
# print the identifier
print(identifier)
# start the app
sys.exit(App.exec())
输出 :
sip.voidptr object at 0x000002A982EED690