回答編集履歴
1
修正d
answer
CHANGED
@@ -2,4 +2,117 @@
|
|
2
2
|
|
3
3
|
以下のチュートリアルを参考にしてください。
|
4
4
|
|
5
|
-
[How to Import a PyQt5 .ui File in a Python GUI - Nitratine](https://nitratine.net/blog/post/how-to-import-a-pyqt5-ui-file-in-a-python-gui/)
|
5
|
+
[How to Import a PyQt5 .ui File in a Python GUI - Nitratine](https://nitratine.net/blog/post/how-to-import-a-pyqt5-ui-file-in-a-python-gui/)
|
6
|
+
|
7
|
+
## 追記
|
8
|
+
|
9
|
+
basic.ui
|
10
|
+
|
11
|
+
```
|
12
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
13
|
+
<ui version="4.0">
|
14
|
+
<class>MainWindow</class>
|
15
|
+
<widget class="QMainWindow" name="MainWindow">
|
16
|
+
<property name="geometry">
|
17
|
+
<rect>
|
18
|
+
<x>0</x>
|
19
|
+
<y>0</y>
|
20
|
+
<width>280</width>
|
21
|
+
<height>72</height>
|
22
|
+
</rect>
|
23
|
+
</property>
|
24
|
+
<property name="windowTitle">
|
25
|
+
<string>MainWindow</string>
|
26
|
+
</property>
|
27
|
+
<widget class="QWidget" name="centralwidget">
|
28
|
+
<widget class="QPushButton" name="printButton">
|
29
|
+
<property name="geometry">
|
30
|
+
<rect>
|
31
|
+
<x>190</x>
|
32
|
+
<y>10</y>
|
33
|
+
<width>81</width>
|
34
|
+
<height>23</height>
|
35
|
+
</rect>
|
36
|
+
</property>
|
37
|
+
<property name="text">
|
38
|
+
<string>Print Content</string>
|
39
|
+
</property>
|
40
|
+
</widget>
|
41
|
+
<widget class="QLineEdit" name="input">
|
42
|
+
<property name="geometry">
|
43
|
+
<rect>
|
44
|
+
<x>10</x>
|
45
|
+
<y>10</y>
|
46
|
+
<width>171</width>
|
47
|
+
<height>20</height>
|
48
|
+
</rect>
|
49
|
+
</property>
|
50
|
+
<property name="placeholderText">
|
51
|
+
<string>Wow! A Placeholder!</string>
|
52
|
+
</property>
|
53
|
+
</widget>
|
54
|
+
<widget class="QPushButton" name="modeButton">
|
55
|
+
<property name="geometry">
|
56
|
+
<rect>
|
57
|
+
<x>10</x>
|
58
|
+
<y>40</y>
|
59
|
+
<width>81</width>
|
60
|
+
<height>23</height>
|
61
|
+
</rect>
|
62
|
+
</property>
|
63
|
+
<property name="text">
|
64
|
+
<string>Mode</string>
|
65
|
+
</property>
|
66
|
+
</widget>
|
67
|
+
<widget class="QPushButton" name="setButton">
|
68
|
+
<property name="geometry">
|
69
|
+
<rect>
|
70
|
+
<x>100</x>
|
71
|
+
<y>40</y>
|
72
|
+
<width>81</width>
|
73
|
+
<height>23</height>
|
74
|
+
</rect>
|
75
|
+
</property>
|
76
|
+
<property name="text">
|
77
|
+
<string>Set</string>
|
78
|
+
</property>
|
79
|
+
</widget>
|
80
|
+
<widget class="QPushButton" name="clearButton">
|
81
|
+
<property name="geometry">
|
82
|
+
<rect>
|
83
|
+
<x>190</x>
|
84
|
+
<y>40</y>
|
85
|
+
<width>81</width>
|
86
|
+
<height>23</height>
|
87
|
+
</rect>
|
88
|
+
</property>
|
89
|
+
<property name="text">
|
90
|
+
<string>Clear</string>
|
91
|
+
</property>
|
92
|
+
</widget>
|
93
|
+
</widget>
|
94
|
+
</widget>
|
95
|
+
<resources/>
|
96
|
+
<connections/>
|
97
|
+
</ui>
|
98
|
+
```
|
99
|
+
|
100
|
+
```python
|
101
|
+
from PyQt5 import QtWidgets, uic
|
102
|
+
import sys
|
103
|
+
|
104
|
+
|
105
|
+
class Ui(QtWidgets.QMainWindow):
|
106
|
+
def __init__(self):
|
107
|
+
super(Ui, self).__init__()
|
108
|
+
ui_class = uic.loadUiType("basic.ui", self)[0]
|
109
|
+
self.ui = ui_class()
|
110
|
+
self.ui.setupUi(self)
|
111
|
+
self.ui.input.setText("hogehoge")
|
112
|
+
|
113
|
+
|
114
|
+
app = QtWidgets.QApplication(sys.argv)
|
115
|
+
window = Ui()
|
116
|
+
window.show()
|
117
|
+
app.exec_()
|
118
|
+
```
|