質問編集履歴

1

コード全体が長いので、手短に知りたいテクニックだけに絞りました。よろしくお願いします。ご指摘ありがとうございます。

2020/05/23 16:55

投稿

FumiKana
FumiKana

スコア1

test CHANGED
File without changes
test CHANGED
@@ -2,74 +2,80 @@
2
2
 
3
3
  def showentry():で今はEntryの.get()を使って表示していますが、加えて、OptionMenuで選ばれたものも表示したいです。
4
4
 
5
+ 以下の部分に修正を加えて、表示したいです。
5
6
 
7
+ entry2 = num_players.get()
6
8
 
9
+ b = tk.Label(text="Numbers: " + entry2, font=("Times New Roman", 18), fg="Green")
10
+
7
- ```class Q0O1(tk.Frame):
11
+ b.place(x=0, y=250)
12
+
13
+ そして、以下がコード全文です。
8
14
 
9
15
 
10
16
 
11
- def __init__(self, home, change):
12
-
13
- tk.Frame.__init__(self, home)
14
-
15
- background = tk.Canvas(self, width=1200, height=800, bg="yellow")
16
-
17
- background.pack()
18
-
19
- back = tk.Button(self, text="Back", font=("Times New Roman", 20, "bold"), command=lambda: change.show_frame(PageOne)).place(x=200, y=600)
20
-
21
- next = tk.Button(self, text="Next", font=("Times New Roman", 20, "bold"), command=showentry)
22
-
23
- next.place(x=900, y=600)
24
-
25
- txt_label = tk.Label(self, text="Put the host name:", font=("Times New Roman", 20, "bold"), fg="black", bg="yellow")
26
-
27
- txt_label.place(x=200, y=50)
28
-
29
- righttop = tk.Label(self, text="Question: 0\nOrders: 1", font=("Time New Roman", 18), fg="Green", bg="yellow")
30
-
31
- righttop.place(x=0, y=100)
32
-
33
- entry_name = tk.Entry(self, width=30, font=("Times New Roman", 20, "bold"))
34
-
35
- entry_name.place(x=500, y=50)
36
-
37
- def showentry():
38
-
39
- a = tk.Label(self, text="Host: "+entry_name.get(), font=("Times New Roman", 18) fg="Green", bg="yellow")
40
-
41
- a.place(x=0, y=200)
42
-
43
- e = tk.Button(self, text="get", width=10, command=showentry)
44
-
45
- e.place(x=0, y=0)
46
-
47
- txt_label_2 = tk.Label(self, text="The number of players:", font=("Times New Roman", 20, "bold"), fg="black", bg="yellow")
48
-
49
- txt_label_2.place(x=200, y=250)
50
-
51
- optionlist = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
52
-
53
- var = tk.StringVar()
54
-
55
- var.set(optionlist[0])
56
-
57
- num_players = tk.OptionMenu(self, var, *optionlist)
58
-
59
- num_players.config(width=20, font=("Times New Roamn", 20, "bold"))
60
-
61
- num_players.place(x=500, y=250)
62
-
63
- txt_label_3 = tk.Label(self, text="The number of rounds:", font=("Times New Roman", 20, "bold"), fg="black", bg="yellow")
64
-
65
- txt_label_3.place(x=200, y=450)
66
-
67
- num_rounds = tk.Entry(self, width=30, font=("Times New Roman", 20, "bold"))
68
-
69
- num_rounds.place(x=500, y=450)
70
17
 
71
18
 
19
+ ```import tkinter as tk
20
+
21
+
22
+
23
+ root = tk.Tk()
24
+
25
+ root.title("First Draft")
26
+
27
+ root.geometry("1000x1000")
28
+
29
+ host = tk.Entry(root, width=30, font=("Times New Roman", 18))
30
+
31
+ host.place(x=500, y=50)
32
+
33
+
34
+
35
+ def showentry():
36
+
37
+ entry = host.get()
38
+
39
+ a = tk.Label(text="Host: " + entry, font=("Times New Roman", 18), fg="Green")
40
+
41
+ a.place(x=0, y=200)
42
+
43
+ entry2 = num_players.get()
44
+
45
+ b = tk.Label(text="Numbers: " + entry2, font=("Times New Roman", 18), fg="Green")
46
+
47
+ b.place(x=0, y=250)
48
+
49
+
50
+
51
+ txt_label = tk.Label(root, text="Put the host name:", font=("Times New Roman", 20), fg="black", bg="yellow")
52
+
53
+ txt_label.place(x=200, y=50)
54
+
55
+ optionlist = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
56
+
57
+ var = tk.StringVar()
58
+
59
+ var.set(optionlist[0])
60
+
61
+ num_players = tk.OptionMenu(root, var, *optionlist)
62
+
63
+ num_players.config(width=10, font=("Times New Roamn", 20))
64
+
65
+ num_players.place(x=500, y=250)
66
+
67
+ btn = tk.Button(root, text="Show Your Choice", font=("Times New Roman", 18), command=showentry).place(x=10, y=10)
68
+
69
+
70
+
71
+
72
+
73
+ root.mainloop()
72
74
 
73
75
  コード
74
76
 
75
77
  ```
78
+
79
+
80
+
81
+ 長文でしたので、簡易的にしました。