📜  PyQt5 QSpinBox – 获取系统标识符

📅  最后修改于: 2022-05-13 01:54:40.845000             🧑  作者: Mango

PyQt5 QSpinBox – 获取系统标识符

在本文中,我们将看到如何获得旋转框的有效窗口系统标识符。有效标识符是指旋转框的原生父窗口系统标识符(ID)。

注意:这个方法应该在主窗口打开后调用,即在主窗口类之外

下面是实现

# 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