【发布时间】:2020-04-09 14:45:37
【问题描述】:
您好,我是 python 新手(直到第 3 课和 MIT 6001 计算机科学和编程导论)
在 Python 中)尽管如此,我还是开始使用 PyQt5 和 Designer(Linux 上的 Python3、PyQt5)。
我读过,对 PyQt5 有一点了解,但对面向对象编程和 Qt 不太了解
文档对我来说就像克林贡语一样。想不通为什么这个脚本 test.py 打不开第二个
窗口,实际上它确实打开了它,我可以在第一个窗口前看到它在 desolve 前短暂显示
当我按下退出按钮时?有什么帮助吗?以及任何可以找到
逻辑的简单资源对于像我这样没有受过教育的人来说,不同类别的 Qt 和应用程序循环。
test.py
!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 8 14:25:12 2020
@author: Pietro
"""
import sys
from PyQt5 import QtWidgets, uic
from PyQt5.QtWidgets import QDesktopWidget
def main():
class quitto(QtWidgets.QMainWindow):
def __init__(self):
super(quitto, self).__init__()
uic.loadUi('exitmain.ui', self)
self.center()
self.show()
print('inside quitting2 ' *5)
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
class menu(QtWidgets.QMainWindow):
def __init__(self):
super(menu, self).__init__()
uic.loadUi('main.ui', self)
self.ButtonQ.clicked.connect(self.QPushButtonQPressed)
self.center()
self.show()
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def QPushButtonQPressed(self):
#This is executed when the button is pressed
print('buttonB pressed' *5)
pippo=quitto()
pippo.show()
app = QtWidgets.QApplication(sys.argv)
window=menu()
app.exec_()
if __name__ == '__main__':
和 main.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="windowModality">
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>520</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<property name="windowIcon">
<iconset resource="resource001.qrc">
<normaloff>:/main/python.png</normaloff>
<normalon>:/main/python.png</normalon>
<disabledoff>:/main/python.png</disabledoff>
<disabledon>:/main/python.png</disabledon>
<activeoff>:/main/python.png</activeoff>
<activeon>:/main/python.png</activeon>
<selectedoff>:/main/python.png</selectedoff>
<selectedon>:/main/python.png</selectedon>:/main/python.png</iconset>
</property>
<property name="styleSheet">
<string notr="true">QPushButton{
background-color: #9de650;
}
QPushButton:hover{
background-color: green;
}
QPushButton#ButtonQ{
background-color: orange;
}
QPushButton#ButtonQ:hover{
background-color: red;
}</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>20</x>
<y>0</y>
<width>471</width>
<height>71</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>16</pointsize>
<weight>75</weight>
<bold>true</bold>
<underline>true</underline>
</font>
</property>
<property name="text">
<string>House-Buying-Menu</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QPushButton" name="ButtonA">
<property name="geometry">
<rect>
<x>170</x>
<y>100</y>
<width>151</width>
<height>81</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>20</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>A</string>
</property>
</widget>
<widget class="QPushButton" name="ButtonB">
<property name="geometry">
<rect>
<x>170</x>
<y>210</y>
<width>151</width>
<height>81</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>20</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>B</string>
</property>
</widget>
<widget class="QPushButton" name="ButtonC">
<property name="geometry">
<rect>
<x>170</x>
<y>320</y>
<width>151</width>
<height>81</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>20</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>C</string>
</property>
</widget>
<widget class="QPushButton" name="ButtonQ">
<property name="geometry">
<rect>
<x>170</x>
<y>450</y>
<width>151</width>
<height>81</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>20</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>QUIT</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>520</width>
<height>29</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources>
<include location="resource001.qrc"/>
</resources>
<connections/>
</ui>
和 mainexit.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>631</width>
<height>496</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>200</x>
<y>310</y>
<width>174</width>
<height>33</height>
</rect>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>631</width>
<height>29</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
【问题讨论】:
标签: python-3.x pyqt5 designer