0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

pyqt5を使って、ボタンを押すと、ダイアログを表示する

Posted at

コード

  1. QtDesigner を使って、画面を作ります。
    • 画面① CountTimer.ui
    • 画面② Input.ui
  2. PyUIC を使って、pyファイルに変更します。
  3. main.pyで以下のコードを書きます。
# わかりやすいため、ボタンイベントのコードを略にします
import sys
import PyQt5
import CountTimer
import Input
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtCore import QTimer, QTime
from PyQt5.QtCore import *

# 画面1
class MyClass(QWidget, CountTimer.Ui_Dialog):

    # 初期化関数
    def __init__(self):
        super(MyClass, self).__init__() 
        self.init_ui()

    # 画面初期化
    def init_ui(self):
        self.setupUi(self)
        self.setWindowTitle("計測タイマー")

# 画面2
class NewClass(QWidget, Input.Ui_Dialog):
    def __init__(self):
        super(NewClass, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("Input")

    def button_set_click(self):
        self.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    mc = MyClass()
    nc = NewClass()
    mc.button_set.clicked.connect(nc.button_set_click)
    mc.show()
    sys.exit(app.exec_())

実行結果

image.png

Set button を押すと、
image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?