Skip to content

Commit a18b2d3

Browse files
committed
add p_38
1 parent 2c70b8f commit a18b2d3

8 files changed

+217
-72
lines changed

LICENSE

Lines changed: 0 additions & 72 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# PyQt5基础教程(持续更新中。。。)
22

3+
* p38_多窗口 [源码下载](p38_多窗口) [博文地址](https://xugaoxiang.com/2023/02/02/pyqt5-38-multiwindow/)
4+
35
* p37_大图片放大缩小 [源码下载](p37_大图片放大缩小) [博文地址](https://xugaoxiang.com/2022/12/06/pyqt5-37-image-zoom/)
46

57
* p36_`QLabel` 滚动条 [源码下载](p36_QLabel滚动条) [博文地址](https://xugaoxiang.com/2022/12/04/pyqt5-36-make-label-scrollable/)

p38_多窗口/main_window.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import sys
2+
3+
from PyQt5.QtWidgets import QMainWindow, QApplication
4+
from ui_mainwindow import Ui_MainWindow
5+
from second_window import SecondWindow
6+
7+
8+
class MainWindow(QMainWindow, Ui_MainWindow):
9+
10+
def __init__(self, parent=None):
11+
super(MainWindow, self).__init__(parent)
12+
self.setupUi(self)
13+
14+
self.pushButton.clicked.connect(self.showSecondWindow)
15+
16+
def showSecondWindow(self):
17+
self.secWin = SecondWindow("Hello SecondWindow.")
18+
self.secWin.show()
19+
20+
21+
if __name__ == '__main__':
22+
app = QApplication(sys.argv)
23+
windows = MainWindow()
24+
windows.show()
25+
sys.exit(app.exec_())

p38_多窗口/mainwindow.ui

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>MainWindow</class>
4+
<widget class="QMainWindow" name="MainWindow">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>800</width>
10+
<height>600</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>多窗口示例</string>
15+
</property>
16+
<widget class="QWidget" name="centralwidget">
17+
<widget class="QPushButton" name="pushButton">
18+
<property name="geometry">
19+
<rect>
20+
<x>310</x>
21+
<y>210</y>
22+
<width>171</width>
23+
<height>91</height>
24+
</rect>
25+
</property>
26+
<property name="font">
27+
<font>
28+
<pointsize>12</pointsize>
29+
</font>
30+
</property>
31+
<property name="text">
32+
<string>开启第二个窗口</string>
33+
</property>
34+
</widget>
35+
</widget>
36+
<widget class="QMenuBar" name="menubar">
37+
<property name="geometry">
38+
<rect>
39+
<x>0</x>
40+
<y>0</y>
41+
<width>800</width>
42+
<height>26</height>
43+
</rect>
44+
</property>
45+
</widget>
46+
<widget class="QStatusBar" name="statusbar"/>
47+
</widget>
48+
<resources/>
49+
<connections/>
50+
</ui>

p38_多窗口/second_window.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from PyQt5.QtWidgets import QMainWindow
2+
from ui_secondwindow import Ui_MainWindow
3+
4+
5+
class SecondWindow(QMainWindow, Ui_MainWindow):
6+
7+
def __init__(self, param, parent=None):
8+
super(SecondWindow, self).__init__(parent)
9+
self.setupUi(self)
10+
11+
print("从主窗口传递过来的字符是:{}".format(param))
12+
self.label.setText(param)

p38_多窗口/secondwindow.ui

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>MainWindow</class>
4+
<widget class="QMainWindow" name="MainWindow">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>800</width>
10+
<height>600</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>第二个窗口</string>
15+
</property>
16+
<widget class="QWidget" name="centralwidget">
17+
<widget class="QLabel" name="label">
18+
<property name="geometry">
19+
<rect>
20+
<x>170</x>
21+
<y>190</y>
22+
<width>501</width>
23+
<height>91</height>
24+
</rect>
25+
</property>
26+
<property name="font">
27+
<font>
28+
<pointsize>14</pointsize>
29+
</font>
30+
</property>
31+
<property name="text">
32+
<string>欢迎访问我的博客,https://xugaoxiang.com</string>
33+
</property>
34+
</widget>
35+
</widget>
36+
<widget class="QMenuBar" name="menubar">
37+
<property name="geometry">
38+
<rect>
39+
<x>0</x>
40+
<y>0</y>
41+
<width>800</width>
42+
<height>26</height>
43+
</rect>
44+
</property>
45+
</widget>
46+
<widget class="QStatusBar" name="statusbar"/>
47+
</widget>
48+
<resources/>
49+
<connections/>
50+
</ui>

p38_多窗口/ui_mainwindow.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Form implementation generated from reading ui file '.\mainwindow.ui'
4+
#
5+
# Created by: PyQt5 UI code generator 5.9.2
6+
#
7+
# WARNING! All changes made in this file will be lost!
8+
9+
from PyQt5 import QtCore, QtGui, QtWidgets
10+
11+
class Ui_MainWindow(object):
12+
def setupUi(self, MainWindow):
13+
MainWindow.setObjectName("MainWindow")
14+
MainWindow.resize(800, 600)
15+
self.centralwidget = QtWidgets.QWidget(MainWindow)
16+
self.centralwidget.setObjectName("centralwidget")
17+
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
18+
self.pushButton.setGeometry(QtCore.QRect(310, 210, 171, 91))
19+
font = QtGui.QFont()
20+
font.setPointSize(12)
21+
self.pushButton.setFont(font)
22+
self.pushButton.setObjectName("pushButton")
23+
MainWindow.setCentralWidget(self.centralwidget)
24+
self.menubar = QtWidgets.QMenuBar(MainWindow)
25+
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
26+
self.menubar.setObjectName("menubar")
27+
MainWindow.setMenuBar(self.menubar)
28+
self.statusbar = QtWidgets.QStatusBar(MainWindow)
29+
self.statusbar.setObjectName("statusbar")
30+
MainWindow.setStatusBar(self.statusbar)
31+
32+
self.retranslateUi(MainWindow)
33+
QtCore.QMetaObject.connectSlotsByName(MainWindow)
34+
35+
def retranslateUi(self, MainWindow):
36+
_translate = QtCore.QCoreApplication.translate
37+
MainWindow.setWindowTitle(_translate("MainWindow", "多窗口示例"))
38+
self.pushButton.setText(_translate("MainWindow", "开启第二个窗口"))
39+

p38_多窗口/ui_secondwindow.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Form implementation generated from reading ui file '.\secondwindow.ui'
4+
#
5+
# Created by: PyQt5 UI code generator 5.9.2
6+
#
7+
# WARNING! All changes made in this file will be lost!
8+
9+
from PyQt5 import QtCore, QtGui, QtWidgets
10+
11+
class Ui_MainWindow(object):
12+
def setupUi(self, MainWindow):
13+
MainWindow.setObjectName("MainWindow")
14+
MainWindow.resize(800, 600)
15+
self.centralwidget = QtWidgets.QWidget(MainWindow)
16+
self.centralwidget.setObjectName("centralwidget")
17+
self.label = QtWidgets.QLabel(self.centralwidget)
18+
self.label.setGeometry(QtCore.QRect(170, 190, 501, 91))
19+
font = QtGui.QFont()
20+
font.setPointSize(14)
21+
self.label.setFont(font)
22+
self.label.setObjectName("label")
23+
MainWindow.setCentralWidget(self.centralwidget)
24+
self.menubar = QtWidgets.QMenuBar(MainWindow)
25+
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
26+
self.menubar.setObjectName("menubar")
27+
MainWindow.setMenuBar(self.menubar)
28+
self.statusbar = QtWidgets.QStatusBar(MainWindow)
29+
self.statusbar.setObjectName("statusbar")
30+
MainWindow.setStatusBar(self.statusbar)
31+
32+
self.retranslateUi(MainWindow)
33+
QtCore.QMetaObject.connectSlotsByName(MainWindow)
34+
35+
def retranslateUi(self, MainWindow):
36+
_translate = QtCore.QCoreApplication.translate
37+
MainWindow.setWindowTitle(_translate("MainWindow", "第二个窗口"))
38+
self.label.setText(_translate("MainWindow", "欢迎访问我的博客,https://xugaoxiang.com"))
39+

0 commit comments

Comments
 (0)