-
-
Save s-nako/1821d3c25997ec4a868f1e5f0bd2f687 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -* | |
import sys | |
from PySide2.QtCore import Qt, QEventLoop | |
from PySide2.QtWidgets import * | |
class MainUi(QWidget): | |
def __init__(self, parent): | |
super(MainUi, self).__init__(parent) | |
main_layout = QHBoxLayout() | |
self.setLayout(main_layout) | |
button1 = QPushButton("getText") | |
button1.clicked.connect(self.show_get_text_dialog) | |
main_layout.addWidget(button1) | |
button2 = QPushButton("getInt") | |
button2.clicked.connect(self.show_get_int_dialog) | |
main_layout.addWidget(button2) | |
button3 = QPushButton("getDouble") | |
button3.clicked.connect(self.show_get_double_dialog) | |
main_layout.addWidget(button3) | |
button4 = QPushButton("getItem") | |
button4.clicked.connect(self.show_get_item_dialog) | |
main_layout.addWidget(button4) | |
def show_get_text_dialog(self): | |
name, ok = QInputDialog.getText(self, 'Name form', 'input name:') | |
if ok: | |
print("input is ", name) | |
def show_get_int_dialog(self): | |
age, ok = QInputDialog.getInt(self, "age", "input age:", minValue=0) | |
if ok: | |
print("input is ", age) | |
def show_get_double_dialog(self): | |
height, ok = QInputDialog.getDouble(self, "height", "input height:", minValue=0) | |
if ok: | |
print("input is ", height) | |
def show_get_item_dialog(self): | |
selected_class, ok = QInputDialog.getItem(self, "class", "select class", ["math", "science", "history"]) | |
if ok: | |
print("input is ", selected_class) | |
# Create a Qt application | |
app = QApplication(sys.argv) | |
main = MainUi(None) | |
main.show() | |
app.exec_() | |
sys.exit() |
I suppose it has to do something with my system, can't get it to work on my mac 12.3.1 (monterey).
It shows a blank window and after a while i'm getting a python crash, this exact code runs fine with PySide6 or pyQt.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this just doesn't work on python 3.9.
This script stalls and gives no errors.