回答編集履歴

1

修正d

2020/09/14 03:45

投稿

tiitoi
tiitoi

スコア21956

test CHANGED
@@ -7,3 +7,229 @@
7
7
 
8
8
 
9
9
  [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/)
10
+
11
+
12
+
13
+ ## 追記
14
+
15
+
16
+
17
+ basic.ui
18
+
19
+
20
+
21
+ ```
22
+
23
+ <?xml version="1.0" encoding="UTF-8"?>
24
+
25
+ <ui version="4.0">
26
+
27
+ <class>MainWindow</class>
28
+
29
+ <widget class="QMainWindow" name="MainWindow">
30
+
31
+ <property name="geometry">
32
+
33
+ <rect>
34
+
35
+ <x>0</x>
36
+
37
+ <y>0</y>
38
+
39
+ <width>280</width>
40
+
41
+ <height>72</height>
42
+
43
+ </rect>
44
+
45
+ </property>
46
+
47
+ <property name="windowTitle">
48
+
49
+ <string>MainWindow</string>
50
+
51
+ </property>
52
+
53
+ <widget class="QWidget" name="centralwidget">
54
+
55
+ <widget class="QPushButton" name="printButton">
56
+
57
+ <property name="geometry">
58
+
59
+ <rect>
60
+
61
+ <x>190</x>
62
+
63
+ <y>10</y>
64
+
65
+ <width>81</width>
66
+
67
+ <height>23</height>
68
+
69
+ </rect>
70
+
71
+ </property>
72
+
73
+ <property name="text">
74
+
75
+ <string>Print Content</string>
76
+
77
+ </property>
78
+
79
+ </widget>
80
+
81
+ <widget class="QLineEdit" name="input">
82
+
83
+ <property name="geometry">
84
+
85
+ <rect>
86
+
87
+ <x>10</x>
88
+
89
+ <y>10</y>
90
+
91
+ <width>171</width>
92
+
93
+ <height>20</height>
94
+
95
+ </rect>
96
+
97
+ </property>
98
+
99
+ <property name="placeholderText">
100
+
101
+ <string>Wow! A Placeholder!</string>
102
+
103
+ </property>
104
+
105
+ </widget>
106
+
107
+ <widget class="QPushButton" name="modeButton">
108
+
109
+ <property name="geometry">
110
+
111
+ <rect>
112
+
113
+ <x>10</x>
114
+
115
+ <y>40</y>
116
+
117
+ <width>81</width>
118
+
119
+ <height>23</height>
120
+
121
+ </rect>
122
+
123
+ </property>
124
+
125
+ <property name="text">
126
+
127
+ <string>Mode</string>
128
+
129
+ </property>
130
+
131
+ </widget>
132
+
133
+ <widget class="QPushButton" name="setButton">
134
+
135
+ <property name="geometry">
136
+
137
+ <rect>
138
+
139
+ <x>100</x>
140
+
141
+ <y>40</y>
142
+
143
+ <width>81</width>
144
+
145
+ <height>23</height>
146
+
147
+ </rect>
148
+
149
+ </property>
150
+
151
+ <property name="text">
152
+
153
+ <string>Set</string>
154
+
155
+ </property>
156
+
157
+ </widget>
158
+
159
+ <widget class="QPushButton" name="clearButton">
160
+
161
+ <property name="geometry">
162
+
163
+ <rect>
164
+
165
+ <x>190</x>
166
+
167
+ <y>40</y>
168
+
169
+ <width>81</width>
170
+
171
+ <height>23</height>
172
+
173
+ </rect>
174
+
175
+ </property>
176
+
177
+ <property name="text">
178
+
179
+ <string>Clear</string>
180
+
181
+ </property>
182
+
183
+ </widget>
184
+
185
+ </widget>
186
+
187
+ </widget>
188
+
189
+ <resources/>
190
+
191
+ <connections/>
192
+
193
+ </ui>
194
+
195
+ ```
196
+
197
+
198
+
199
+ ```python
200
+
201
+ from PyQt5 import QtWidgets, uic
202
+
203
+ import sys
204
+
205
+
206
+
207
+
208
+
209
+ class Ui(QtWidgets.QMainWindow):
210
+
211
+ def __init__(self):
212
+
213
+ super(Ui, self).__init__()
214
+
215
+ ui_class = uic.loadUiType("basic.ui", self)[0]
216
+
217
+ self.ui = ui_class()
218
+
219
+ self.ui.setupUi(self)
220
+
221
+ self.ui.input.setText("hogehoge")
222
+
223
+
224
+
225
+
226
+
227
+ app = QtWidgets.QApplication(sys.argv)
228
+
229
+ window = Ui()
230
+
231
+ window.show()
232
+
233
+ app.exec_()
234
+
235
+ ```