回答編集履歴
1
追記
test
CHANGED
@@ -31,3 +31,185 @@
|
|
31
31
|
y_ent.insert(0, y)
|
32
32
|
|
33
33
|
```
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
## 追記:円の大きさを倍率に合わせる
|
38
|
+
|
39
|
+
試行錯誤していたら、円の大きさを倍率に合わせることができたので貼っておきます。
|
40
|
+
|
41
|
+
正確な理屈は理解できていませんが。
|
42
|
+
|
43
|
+
```Python
|
44
|
+
|
45
|
+
import tkinter as tk
|
46
|
+
|
47
|
+
from tkinter import *
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
g_scale = 1.0 # 累積倍率
|
52
|
+
|
53
|
+
g_tagno = 1 # 各円のタグ名。新規追加した円のみスケーリングするために。
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
def pos(event):
|
58
|
+
|
59
|
+
x = int(canvas.canvasx(event.x))
|
60
|
+
|
61
|
+
y = int(canvas.canvasy(event.y))
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
canvas.delete("line")
|
66
|
+
|
67
|
+
x_ent.delete(0, tk.END)
|
68
|
+
|
69
|
+
x_ent.insert(0, x)
|
70
|
+
|
71
|
+
y_ent.delete(0, tk.END)
|
72
|
+
|
73
|
+
y_ent.insert(0, y)
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
def lclick(event):
|
78
|
+
|
79
|
+
x, y = int(x_ent.get()), int(y_ent.get())
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
global g_tagno
|
84
|
+
|
85
|
+
tag = 'temp{}'.format(g_tagno)
|
86
|
+
|
87
|
+
canvas.create_oval(x-5, y-5, x+5, y+5, activefill = 'black',fill='red',tag=tag)
|
88
|
+
|
89
|
+
g_tagno += 1
|
90
|
+
|
91
|
+
canvas.scale(tag, x, y, g_scale, g_scale) # この円だけスケーリングする
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
def zoomer(event):
|
96
|
+
|
97
|
+
sf = 1.1 if event.delta > 0 else 0.9
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
# 累積倍率を記録しておく
|
102
|
+
|
103
|
+
global g_scale
|
104
|
+
|
105
|
+
g_scale *= sf
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
canvas.scale("all", 0,0,sf, sf)
|
110
|
+
|
111
|
+
canvas.configure(scrollregion=canvas.bbox("all"))
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
# 以下は変わらず
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
def move_start(event):
|
120
|
+
|
121
|
+
canvas.scan_mark(event.x, event.y)
|
122
|
+
|
123
|
+
def move_move(event):
|
124
|
+
|
125
|
+
canvas.scan_dragto(event.x, event.y, gain=1)
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
def show_width(event):
|
130
|
+
|
131
|
+
window_width.delete(0, tk.END)
|
132
|
+
|
133
|
+
window_width.insert(0, event.width)
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
window = tk.Tk()
|
138
|
+
|
139
|
+
window.title('サンプル')
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
frame_T = tk.Frame(window,bd=1,relief="ridge")
|
144
|
+
|
145
|
+
frame_T.grid(row=0, column=0,sticky='news')
|
146
|
+
|
147
|
+
frame1_1 = tk.Frame(window,bd=1,relief="ridge")
|
148
|
+
|
149
|
+
frame1_1.grid(row=1, column=0,sticky='news')
|
150
|
+
|
151
|
+
frame_main = tk.Frame(window,bd=1,relief="ridge")
|
152
|
+
|
153
|
+
frame_main.grid(row=2, column=0,sticky='news')
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
y_ent = tk.Entry(frame_T)
|
158
|
+
|
159
|
+
y_ent.pack(side=RIGHT)
|
160
|
+
|
161
|
+
x_ent = tk.Entry(frame_T)
|
162
|
+
|
163
|
+
x_ent.pack(side=RIGHT)
|
164
|
+
|
165
|
+
window_width = tk.Entry(frame_T)
|
166
|
+
|
167
|
+
window_width.pack(side=RIGHT)
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
canvas = tk.Canvas(master = frame_main, height=600, width=1000, bg='white',bd=1,relief="ridge")
|
172
|
+
|
173
|
+
canvas.grid(row=0, column=0,sticky='news')
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
xsb = tk.Scrollbar(frame_main, orient="horizontal", command=canvas.xview)
|
178
|
+
|
179
|
+
ysb = tk.Scrollbar(frame_main, orient="vertical", command=canvas.yview)
|
180
|
+
|
181
|
+
canvas.configure(yscrollcommand=ysb.set, xscrollcommand=xsb.set)
|
182
|
+
|
183
|
+
xsb.grid(row=1, column=0,sticky="ew")
|
184
|
+
|
185
|
+
ysb.grid(row=0, column=1, sticky="ns")
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
canvas.bind('<Motion>', pos)
|
190
|
+
|
191
|
+
canvas.bind('<Button-1>', lclick)
|
192
|
+
|
193
|
+
canvas.bind("<MouseWheel>",zoomer)
|
194
|
+
|
195
|
+
canvas.bind("<ButtonPress-3>", move_start)
|
196
|
+
|
197
|
+
canvas.bind("<B3-Motion>", move_move)
|
198
|
+
|
199
|
+
canvas.bind("<Configure>", show_width)
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
frame_main.grid_columnconfigure(0,weight=1)
|
204
|
+
|
205
|
+
frame_main.grid_rowconfigure(0,weight=1)
|
206
|
+
|
207
|
+
window.grid_columnconfigure(0,weight=1)
|
208
|
+
|
209
|
+
window.grid_rowconfigure(2,weight=1)
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
window.mainloop()
|
214
|
+
|
215
|
+
```
|