Qt6 Python QtCreator メニューの作成

Qt6 Python QtCreator メニューの作成

QtCreatorでkakeiプロジェクトを作成

kakei.py kakeid.ui ui_kakeid を作成 (pyside6-uic kakeid.ui -o ui_kakeid.py)

kakei.py

# This Python file uses the following encoding: utf-8
import sys
import os
import subprocess

from PySide6.QtWidgets import QApplication, QMainWindow

# Important:
# You need to run the following command to generate the ui_form.py file
#     pyside6-uic form.ui -o ui_form.py, or
#     pyside2-uic form.ui -o ui_form.py
from ui_kakeid import Ui_kakei

class kakei(QMainWindow):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.ui = Ui_kakei()
        self.ui.setupUi(self)

        self.ui.pushButton.clicked.connect(self.end)
        self.ui.pushButton_2.clicked.connect(self.shtorihikisaki)
        self.ui.pushButton_3.clicked.connect(self.inptorihiki)
        self.ui.pushButton_4.clicked.connect(self.main_PassValue)
        self.ui.pushButton_5.clicked.connect(self.mntginkou)
        self.ui.pushButton_6.clicked.connect(self.torihikisakizan)
        self.ui.pushButton_7.clicked.connect(self.shiharaisakizan)
        self.ui.pushButton_8.clicked.connect(self.torihikisakimei)
        self.ui.pushButton_9.clicked.connect(self.shiharaisakimei)

        self.ui.label.setStyleSheet("background-color: pink")
        self.ui.pushButton.setStyleSheet("background-color: orange")
        self.ui.pushButton_2.setStyleSheet("background-color: lavender")
        self.ui.pushButton_3.setStyleSheet("background-color: lavender")
        self.ui.pushButton_4.setStyleSheet("background-color: lavender")
        self.ui.pushButton_5.setStyleSheet("background-color: lavender")
        self.ui.pushButton_6.setStyleSheet("background-color: lavender")
        self.ui.pushButton_7.setStyleSheet("background-color: lavender")
        self.ui.pushButton_8.setStyleSheet("background-color: lavender")
        self.ui.pushButton_9.setStyleSheet("background-color: lavender")

    def end(self):
        self.close()

    def shtorihikisaki(self):
        os.chdir(os.path.dirname(os.path.abspath(__file__)))
        try:
           subprocess.Popen(['python3','shtorihikisaki.py'], shell=False)
        except:
           subprocess.Popen(['python','shtorihikisaki.py'], shell=False)

    def inptorihiki(self):
        os.chdir(os.path.dirname(os.path.abspath(__file__)))
        try:
           subprocess.Popen(['python3','inptorihiki.py'], shell=False)
        except:
           subprocess.Popen(['python','inptorihiki.py'], shell=False)

    def main_PassValue(self):
        os.chdir(os.path.dirname(os.path.abspath(__file__)))
        try:
           subprocess.Popen(['python3','mnttorihikisaki.py'], shell=False)
        except:
           subprocess.Popen(['python','mnttorihikisaki.py'], shell=False)

    def mntginkou(self):
        os.chdir(os.path.dirname(os.path.abspath(__file__)))
        try:
           subprocess.Popen(['python3','mntginkou.py'], shell=False)
        except:
           subprocess.Popen(['python','mntginkou.py'], shell=False)

    def torihikisakizan(self):
        os.chdir(os.path.dirname(os.path.abspath(__file__)))
        try:
           subprocess.Popen(['python3','torihikisakizan.py'], shell=False)
        except:
           subprocess.Popen(['python','torihikisakizan.py'], shell=False)

    def shiharaisakizan(self):
        os.chdir(os.path.dirname(os.path.abspath(__file__)))
        try:
           subprocess.Popen(['python3','shiharaisakizan.py'], shell=False)
        except:
           subprocess.Popen(['python','shiharaisakizan.py'], shell=False)

    def torihikisakimei(self):
        os.chdir(os.path.dirname(os.path.abspath(__file__)))
        try:
           subprocess.Popen(['python3','torihikisakimei.py'], shell=False)
        except:
           subprocess.Popen(['python','torihikisakimei.py'], shell=False)

    def shiharaisakimei(self):
        os.chdir(os.path.dirname(os.path.abspath(__file__)))
        try:
           subprocess.Popen(['python3','shiharaisakimei.py'], shell=False)
        except:
           subprocess.Popen(['python','shiharaisakimei.py'], shell=False)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    widget = kakei()
    widget.show()
    sys.exit(app.exec())

kakei.pyのフォルダーへ実行するものをセットします。os.chdirでkakei.pyのディレクトリパスをセットします。

実行画面

PAGE TOP