質問編集履歴
2
表記方法の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,6 +30,8 @@
|
|
30
30
|
|
31
31
|
手続き型では下記のように記入しました。
|
32
32
|
|
33
|
+
```python
|
34
|
+
|
33
35
|
# GUIの作成
|
34
36
|
|
35
37
|
import tkinter as tk
|
@@ -52,7 +54,7 @@
|
|
52
54
|
|
53
55
|
|
54
56
|
|
55
|
-
Scrollbar を生成して配置
|
57
|
+
#Scrollbar を生成して配置
|
56
58
|
|
57
59
|
bar_y = tk.Scrollbar(root, orient=tk.VERTICAL)
|
58
60
|
|
@@ -70,8 +72,6 @@
|
|
70
72
|
|
71
73
|
|
72
74
|
|
73
|
-
Canvas Widget を配置
|
74
|
-
|
75
75
|
canvas.config(yscrollcommand=bar_y.set, xscrollcommand=bar_x.set)
|
76
76
|
|
77
77
|
canvas.config(scrollregion=(0, 0, 4000, 5000)) # スクロール範囲
|
@@ -80,13 +80,13 @@
|
|
80
80
|
|
81
81
|
|
82
82
|
|
83
|
-
Frame Widgetを 生成
|
83
|
+
# Frame Widgetを 生成
|
84
84
|
|
85
85
|
frame = tk.Frame(canvas)
|
86
86
|
|
87
87
|
|
88
88
|
|
89
|
-
Frame Widgetを Canvas Widget上に配置
|
89
|
+
# Frame Widgetを Canvas Widget上に配置
|
90
90
|
|
91
91
|
canvas.create_window((0, 0), window=frame, anchor=tk.NW, width=canvas.cget('width'))
|
92
92
|
|
@@ -146,7 +146,7 @@
|
|
146
146
|
|
147
147
|
|
148
148
|
|
149
|
-
Scrollbar を生成して配置
|
149
|
+
# Scrollbar を生成して配置
|
150
150
|
|
151
151
|
self.bar_y = tk.Scrollbar(self, orient=tk.VERTICAL)
|
152
152
|
|
@@ -166,7 +166,7 @@
|
|
166
166
|
|
167
167
|
self.config(yscrollcommand=self.bar_y.set, xscrollcommand=self.bar_x.set)
|
168
168
|
|
169
|
-
self.config(scrollregion=(0, 0, 4000, 5000)) スクロール範囲
|
169
|
+
self.config(scrollregion=(0, 0, 4000, 5000)) # スクロール範囲
|
170
170
|
|
171
171
|
self.pack(fill=tk.BOTH, expand=tk.YES)
|
172
172
|
|
@@ -235,3 +235,5 @@
|
|
235
235
|
if __name__ == "__main__":
|
236
236
|
|
237
237
|
main()
|
238
|
+
|
239
|
+
```
|
1
オブジェクト指向として書いたコードを追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,6 +32,12 @@
|
|
32
32
|
|
33
33
|
# GUIの作成
|
34
34
|
|
35
|
+
import tkinter as tk
|
36
|
+
|
37
|
+
import tkinter.ttk as ttk
|
38
|
+
|
39
|
+
|
40
|
+
|
35
41
|
root = tk.Tk()
|
36
42
|
|
37
43
|
root.geometry('2000x1500')
|
@@ -104,16 +110,128 @@
|
|
104
110
|
|
105
111
|
|
106
112
|
|
107
|
-
notebook.add(tab1, text='
|
113
|
+
notebook.add(tab1, text='tab1')
|
108
|
-
|
114
|
+
|
109
|
-
notebook.add(tab2, text='
|
115
|
+
notebook.add(tab2, text='tab2')
|
110
|
-
|
116
|
+
|
111
|
-
notebook.add(tab3, text='
|
117
|
+
notebook.add(tab3, text='tab3')
|
112
|
-
|
118
|
+
|
113
|
-
notebook.add(tab4, text='
|
119
|
+
notebook.add(tab4, text='tab4')
|
114
|
-
|
120
|
+
|
115
|
-
notebook.add(tab5, text='
|
121
|
+
notebook.add(tab5, text='tab5')
|
116
|
-
|
122
|
+
|
117
|
-
notebook.add(tab6, text='
|
123
|
+
notebook.add(tab6, text='tab6')
|
118
124
|
|
119
125
|
notebook.pack(expand=True, fill='both')
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
# オブジェクト指向での記入
|
130
|
+
|
131
|
+
import tkinter as tk
|
132
|
+
|
133
|
+
import tkinter.ttk as ttk
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
class Application(tk.Canvas):
|
140
|
+
|
141
|
+
def __init__(self, master=None):
|
142
|
+
|
143
|
+
super().__init__(master, width=2000, height=1000)
|
144
|
+
|
145
|
+
self.master.title('CBD')
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
Scrollbar を生成して配置
|
150
|
+
|
151
|
+
self.bar_y = tk.Scrollbar(self, orient=tk.VERTICAL)
|
152
|
+
|
153
|
+
self.bar_y.pack(side=tk.RIGHT, fill=tk.Y)
|
154
|
+
|
155
|
+
self.bar_y.config(command=self.yview)
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
self.bar_x = tk.Scrollbar(self, orient=tk.HORIZONTAL)
|
160
|
+
|
161
|
+
self.bar_x.pack(side=tk.BOTTOM, fill=tk.X)
|
162
|
+
|
163
|
+
self.bar_x.config(command=self.xview)
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
self.config(yscrollcommand=self.bar_y.set, xscrollcommand=self.bar_x.set)
|
168
|
+
|
169
|
+
self.config(scrollregion=(0, 0, 4000, 5000)) スクロール範囲
|
170
|
+
|
171
|
+
self.pack(fill=tk.BOTH, expand=tk.YES)
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
self.frame = tk.Frame(self)
|
176
|
+
|
177
|
+
self.create_window((0, 0), window=self.frame, anchor=tk.NW, width=self.cget('width'))
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
nootebook = ttk.Notebook(self.frame)
|
182
|
+
|
183
|
+
Note(master=nootebook)
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
class Note(nootebook):
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
def __init__(self, master=None):
|
192
|
+
|
193
|
+
super().__init__(master)
|
194
|
+
|
195
|
+
self.master.title('window')
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
tab1 = tk.Frame(self.master)
|
200
|
+
|
201
|
+
self.add(tab1, text="tab1")
|
202
|
+
|
203
|
+
Tab1(master=tab1)
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
tab2 = tk.Frame(self.master)
|
208
|
+
|
209
|
+
self.add(tab2, text="tab2")
|
210
|
+
|
211
|
+
Tab2(master=tab2)
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
self._quit_outside_widget()
|
216
|
+
|
217
|
+
self.pack()
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
def main():
|
224
|
+
|
225
|
+
root = tk.Tk()
|
226
|
+
|
227
|
+
app = Application(master=root) # Inherit
|
228
|
+
|
229
|
+
app.mainloop()
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
if __name__ == "__main__":
|
236
|
+
|
237
|
+
main()
|