質問編集履歴
5
追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -321,3 +321,7 @@
|
|
321
321
|
main()
|
322
322
|
|
323
323
|
```
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
![イメージ説明](3acaf48927c5ed6f218df62d3a28251b.jpeg)
|
4
追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -159,3 +159,165 @@
|
|
159
159
|
main()
|
160
160
|
|
161
161
|
```
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
# 追記
|
166
|
+
|
167
|
+
```Python
|
168
|
+
|
169
|
+
from tkinter import font
|
170
|
+
|
171
|
+
from tkinter import ttk
|
172
|
+
|
173
|
+
import tkinter as tk
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
class App:
|
178
|
+
|
179
|
+
def __init__(self, win):
|
180
|
+
|
181
|
+
self.win = win
|
182
|
+
|
183
|
+
self.win.geometry("1000x700")
|
184
|
+
|
185
|
+
self.create_view()
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
def create_view(self):
|
190
|
+
|
191
|
+
self.win.rowconfigure(tuple(range(2)), weight=1)
|
192
|
+
|
193
|
+
self.win.columnconfigure(tuple(range(2)), weight=1)
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
columns = 5
|
198
|
+
|
199
|
+
data = []
|
200
|
+
|
201
|
+
for i in range(0, 100, 5):
|
202
|
+
|
203
|
+
data.append([str(i)+"abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaa", str(i+1), str(i+2), str(i+3), str(i+4)])
|
204
|
+
|
205
|
+
self.tree = ttk.Treeview(self.win)
|
206
|
+
|
207
|
+
ttk.Style().configure("Treeview.Heading", font=("", 30))
|
208
|
+
|
209
|
+
fontsize = 30
|
210
|
+
|
211
|
+
treefont = font.Font(size=fontsize)
|
212
|
+
|
213
|
+
ttk.Style().configure("Treeview", font=("", fontsize), rowheight=treefont.metrics()["linespace"])
|
214
|
+
|
215
|
+
self.tree.grid(row=0, column=0, rowspan=2, columnspan=2, sticky="nsew", padx=5, pady=5)
|
216
|
+
|
217
|
+
self.tree["columns"] = tuple(range(1, columns + 1))
|
218
|
+
|
219
|
+
self.tree["show"] = "headings"
|
220
|
+
|
221
|
+
width_li = [0, 0, 0, 0, 0]
|
222
|
+
|
223
|
+
#w = self.win.winfo_width()
|
224
|
+
|
225
|
+
#ww = int(w / 7)
|
226
|
+
|
227
|
+
for i in range(1, columns + 1):
|
228
|
+
|
229
|
+
txt = "Data"+str(i)
|
230
|
+
|
231
|
+
self.tree.heading(i, text=txt)
|
232
|
+
|
233
|
+
if width_li[i-1] < treefont.measure(txt):
|
234
|
+
|
235
|
+
width_li[i-1] = treefont.measure(txt)
|
236
|
+
|
237
|
+
#id = None
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
for i in data:
|
242
|
+
|
243
|
+
for j in range(len(i)):
|
244
|
+
|
245
|
+
if width_li[j] < treefont.measure(i[j]):
|
246
|
+
|
247
|
+
width_li[j] = treefont.measure(i[j])
|
248
|
+
|
249
|
+
self.tree.insert("", "end", value=(i))
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
for i in range(1, columns + 1):
|
254
|
+
|
255
|
+
self.tree.column(i, stretch=False, width=width_li[i-1])
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
#self.tree.see(id)
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
self.button1 = tk.Button(self.win, text="▲", command=self.push_button1)
|
264
|
+
|
265
|
+
self.button1.grid(row=0, column=2, sticky="nsew")
|
266
|
+
|
267
|
+
self.button2 = tk.Button(self.win, text="▼", command=self.push_button2)
|
268
|
+
|
269
|
+
self.button2.grid(row=1, column=2, sticky="nsew")
|
270
|
+
|
271
|
+
self.button3 = tk.Button(self.win, text="◀", command=self.push_button3)
|
272
|
+
|
273
|
+
self.button3.grid(row=2, column=0, sticky="nsew")
|
274
|
+
|
275
|
+
self.button4 = tk.Button(self.win, text="▶", command=self.push_button4)
|
276
|
+
|
277
|
+
self.button4.grid(row=2, column=1, sticky="nsew")
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
def push_button1(self):
|
282
|
+
|
283
|
+
self.tree.yview("scroll", -1, "units")
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
def push_button2(self):
|
288
|
+
|
289
|
+
self.tree.yview("scroll", +1, "units")
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
def push_button3(self):
|
294
|
+
|
295
|
+
self.tree.xview("scroll", -1, "pages")
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
def push_button4(self):
|
300
|
+
|
301
|
+
self.tree.xview("scroll", +1, "pages")
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
def main():
|
310
|
+
|
311
|
+
win = tk.Tk()
|
312
|
+
|
313
|
+
App(win)
|
314
|
+
|
315
|
+
win.mainloop()
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
if __name__ == "__main__":
|
320
|
+
|
321
|
+
main()
|
322
|
+
|
323
|
+
```
|
3
変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -48,7 +48,7 @@
|
|
48
48
|
|
49
49
|
for i in range(0, 100, 5):
|
50
50
|
|
51
|
-
data.append([str(i)+"abcdefghijklmnopqrstuvwxyz", str(i+1), str(i+2), str(i+3), str(i+4)])
|
51
|
+
data.append([str(i)+"abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", str(i+1), str(i+2), str(i+3), str(i+4)])
|
52
52
|
|
53
53
|
self.tree = ttk.Treeview(self.win)
|
54
54
|
|
@@ -87,6 +87,8 @@
|
|
87
87
|
if width_li[j] < len(i[j]):
|
88
88
|
|
89
89
|
width_li[j] = len(i[j])
|
90
|
+
|
91
|
+
print(width_li)
|
90
92
|
|
91
93
|
id = self.tree.insert("", "end", value=(i))
|
92
94
|
|
2
変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,7 +8,13 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
+
以下、len()で取得した値をwidthに入れようとしたときのコードです。間違っていたらすみません。
|
12
|
+
|
13
|
+
|
14
|
+
|
11
15
|
```Python
|
16
|
+
|
17
|
+
from tkinter import font
|
12
18
|
|
13
19
|
from tkinter import ttk
|
14
20
|
|
@@ -46,6 +52,14 @@
|
|
46
52
|
|
47
53
|
self.tree = ttk.Treeview(self.win)
|
48
54
|
|
55
|
+
ttk.Style().configure("Treeview.Heading", font=("", 30))
|
56
|
+
|
57
|
+
fontsize = 30
|
58
|
+
|
59
|
+
treefont = font.Font(size=fontsize)
|
60
|
+
|
61
|
+
ttk.Style().configure("Treeview", font=("", fontsize), rowheight=treefont.metrics()["linespace"])
|
62
|
+
|
49
63
|
self.tree.grid(row=0, column=0, rowspan=2, columnspan=2, sticky="nsew", padx=5, pady=5)
|
50
64
|
|
51
65
|
self.tree["columns"] = tuple(range(1, columns + 1))
|
@@ -62,15 +76,21 @@
|
|
62
76
|
|
63
77
|
#self.tree.column(i, width=ww)
|
64
78
|
|
65
|
-
|
79
|
+
id = None
|
66
80
|
|
67
|
-
id =
|
81
|
+
width_li = [100, 100, 100, 100, 100] # width初期値
|
68
82
|
|
69
83
|
for i in data:
|
70
84
|
|
85
|
+
for j in range(len(i)):
|
86
|
+
|
87
|
+
if width_li[j] < len(i[j]):
|
88
|
+
|
89
|
+
width_li[j] = len(i[j])
|
90
|
+
|
71
91
|
id = self.tree.insert("", "end", value=(i))
|
72
92
|
|
73
|
-
|
93
|
+
|
74
94
|
|
75
95
|
self.tree.see(id)
|
76
96
|
|
@@ -116,7 +136,7 @@
|
|
116
136
|
|
117
137
|
self.tree.xview("scroll", +1, "pages")
|
118
138
|
|
119
|
-
|
139
|
+
|
120
140
|
|
121
141
|
|
122
142
|
|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
TkinterのTreeviewで表を作成したときに、初回表示時はデータのすべてが見えるようにするオプションはありますか?
|
2
2
|
|
3
|
-
w
|
3
|
+
(ウィンドウそのものの大きさ、Treeviewの大きさを全体的に広げるのは無し。あとの方の列についてはスクロールして見えればいいですが、列幅は自分で操作したくない。)
|
4
4
|
|
5
5
|
|
6
6
|
|