回答編集履歴
1
コードの追加
test
CHANGED
@@ -6,3 +6,58 @@
|
|
6
6
|
1行で繋げて書くことで``textBox1``に``None``が代入されてしまいます。
|
7
7
|
他のテキストボックスについても同様です。
|
8
8
|
|
9
|
+
またx1~x6についても戻り値にするのではなく、global変数にする必要があるかと思います。
|
10
|
+
```
|
11
|
+
import tkinter as tk
|
12
|
+
|
13
|
+
|
14
|
+
# Tkインスタンスの作成
|
15
|
+
root = tk.Tk()
|
16
|
+
|
17
|
+
# ウィンドウのサイズを設定
|
18
|
+
root.geometry('500x330')
|
19
|
+
# 画面タイトル
|
20
|
+
root.title('変数を入力してください')
|
21
|
+
|
22
|
+
# ラベル
|
23
|
+
label1 = tk.Label(text='text1').place(x=30, y=30)
|
24
|
+
label2 = tk.Label(text='text2').place(x=30, y=70)
|
25
|
+
label3 = tk.Label(text='text3').place(x=30, y=110)
|
26
|
+
label4 = tk.Label(text='text4').place(x=30, y=150)
|
27
|
+
label5 = tk.Label(text='text5').place(x=30, y=190)
|
28
|
+
label6 = tk.Label(text='text6').place(x=30, y=230)
|
29
|
+
|
30
|
+
# テキストボックス
|
31
|
+
textBox1 = tk.Entry(width=30)
|
32
|
+
textBox1.place(x=250, y=30)
|
33
|
+
textBox2 = tk.Entry(width=30)
|
34
|
+
textBox2.place(x=250, y=70)
|
35
|
+
textBox3 = tk.Entry(width=30)
|
36
|
+
textBox3.place(x=250, y=110)
|
37
|
+
textBox4 = tk.Entry(width=30)
|
38
|
+
textBox4.place(x=250, y=150)
|
39
|
+
textBox5 = tk.Entry(width=30)
|
40
|
+
textBox5.place(x=250, y=190)
|
41
|
+
textBox6 = tk.Entry(width=30)
|
42
|
+
textBox6.place(x=250, y=230)
|
43
|
+
|
44
|
+
# テキストボックスの値を取得
|
45
|
+
def val():
|
46
|
+
global x1, x2, x3, x4, x5, x6
|
47
|
+
x1 = textBox1.get()
|
48
|
+
x2 = textBox2.get()
|
49
|
+
x3 = textBox3.get()
|
50
|
+
x4 = textBox4.get()
|
51
|
+
x5 = textBox5.get()
|
52
|
+
x6 = textBox6.get()
|
53
|
+
|
54
|
+
# ボタンの作成と配置
|
55
|
+
button = tk.Button(root,
|
56
|
+
text = '送信',
|
57
|
+
# クリック時にval()関数を呼ぶ
|
58
|
+
command = val
|
59
|
+
).place(x=30, y=270)
|
60
|
+
|
61
|
+
root.mainloop()
|
62
|
+
```
|
63
|
+
|