質問編集履歴
1
コード全体が長いので、手短に知りたいテクニックだけに絞りました。よろしくお願いします。ご指摘ありがとうございます。
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -1,38 +1,41 @@
|
|
|
1
1
|
Entryを使って、.get()で表示することはできるのですが、OptionMenuのドロップダウンリストで選ばれたものを表示することができません。
|
|
2
2
|
def showentry():で今はEntryの.get()を使って表示していますが、加えて、OptionMenuで選ばれたものも表示したいです。
|
|
3
|
+
以下の部分に修正を加えて、表示したいです。
|
|
4
|
+
entry2 = num_players.get()
|
|
5
|
+
b = tk.Label(text="Numbers: " + entry2, font=("Times New Roman", 18), fg="Green")
|
|
6
|
+
b.place(x=0, y=250)
|
|
7
|
+
そして、以下がコード全文です。
|
|
3
8
|
|
|
4
|
-
```class Q0O1(tk.Frame):
|
|
5
9
|
|
|
6
|
-
def __init__(self, home, change):
|
|
7
|
-
tk.Frame.__init__(self, home)
|
|
8
|
-
background = tk.Canvas(self, width=1200, height=800, bg="yellow")
|
|
9
|
-
background.pack()
|
|
10
|
-
back = tk.Button(self, text="Back", font=("Times New Roman", 20, "bold"), command=lambda: change.show_frame(PageOne)).place(x=200, y=600)
|
|
11
|
-
next = tk.Button(self, text="Next", font=("Times New Roman", 20, "bold"), command=showentry)
|
|
12
|
-
next.place(x=900, y=600)
|
|
13
|
-
txt_label = tk.Label(self, text="Put the host name:", font=("Times New Roman", 20, "bold"), fg="black", bg="yellow")
|
|
14
|
-
txt_label.place(x=200, y=50)
|
|
15
|
-
righttop = tk.Label(self, text="Question: 0\nOrders: 1", font=("Time New Roman", 18), fg="Green", bg="yellow")
|
|
16
|
-
righttop.place(x=0, y=100)
|
|
17
|
-
entry_name = tk.Entry(self, width=30, font=("Times New Roman", 20, "bold"))
|
|
18
|
-
entry_name.place(x=500, y=50)
|
|
19
|
-
def showentry():
|
|
20
|
-
a = tk.Label(self, text="Host: "+entry_name.get(), font=("Times New Roman", 18) fg="Green", bg="yellow")
|
|
21
|
-
a.place(x=0, y=200)
|
|
22
|
-
e = tk.Button(self, text="get", width=10, command=showentry)
|
|
23
|
-
e.place(x=0, y=0)
|
|
24
|
-
txt_label_2 = tk.Label(self, text="The number of players:", font=("Times New Roman", 20, "bold"), fg="black", bg="yellow")
|
|
25
|
-
txt_label_2.place(x=200, y=250)
|
|
26
|
-
optionlist = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
|
|
27
|
-
|
|
10
|
+
```import tkinter as tk
|
|
28
|
-
var.set(optionlist[0])
|
|
29
|
-
num_players = tk.OptionMenu(self, var, *optionlist)
|
|
30
|
-
num_players.config(width=20, font=("Times New Roamn", 20, "bold"))
|
|
31
|
-
num_players.place(x=500, y=250)
|
|
32
|
-
txt_label_3 = tk.Label(self, text="The number of rounds:", font=("Times New Roman", 20, "bold"), fg="black", bg="yellow")
|
|
33
|
-
txt_label_3.place(x=200, y=450)
|
|
34
|
-
num_rounds = tk.Entry(self, width=30, font=("Times New Roman", 20, "bold"))
|
|
35
|
-
num_rounds.place(x=500, y=450)
|
|
36
11
|
|
|
12
|
+
root = tk.Tk()
|
|
13
|
+
root.title("First Draft")
|
|
14
|
+
root.geometry("1000x1000")
|
|
15
|
+
host = tk.Entry(root, width=30, font=("Times New Roman", 18))
|
|
16
|
+
host.place(x=500, y=50)
|
|
17
|
+
|
|
18
|
+
def showentry():
|
|
19
|
+
entry = host.get()
|
|
20
|
+
a = tk.Label(text="Host: " + entry, font=("Times New Roman", 18), fg="Green")
|
|
21
|
+
a.place(x=0, y=200)
|
|
22
|
+
entry2 = num_players.get()
|
|
23
|
+
b = tk.Label(text="Numbers: " + entry2, font=("Times New Roman", 18), fg="Green")
|
|
24
|
+
b.place(x=0, y=250)
|
|
25
|
+
|
|
26
|
+
txt_label = tk.Label(root, text="Put the host name:", font=("Times New Roman", 20), fg="black", bg="yellow")
|
|
27
|
+
txt_label.place(x=200, y=50)
|
|
28
|
+
optionlist = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
|
|
29
|
+
var = tk.StringVar()
|
|
30
|
+
var.set(optionlist[0])
|
|
31
|
+
num_players = tk.OptionMenu(root, var, *optionlist)
|
|
32
|
+
num_players.config(width=10, font=("Times New Roamn", 20))
|
|
33
|
+
num_players.place(x=500, y=250)
|
|
34
|
+
btn = tk.Button(root, text="Show Your Choice", font=("Times New Roman", 18), command=showentry).place(x=10, y=10)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
root.mainloop()
|
|
37
38
|
コード
|
|
38
|
-
```
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
長文でしたので、簡易的にしました。
|