iT邦幫忙

0

為什麼在text無法出現我所點選的項目呢?

  • 分享至 

  • xImage
import tkinter as tk
def insert_order(msg):
    text.insert(tk.INSERT,msg) 
def reason():
    global e1
    global win2
    var1=tk.StringVar()
    if(option.get()==word[0]):
        win2=tk.Tk()
        win2.geometry("200x200")
        tk.Label(win2,text="which one do you want?").grid(row=0,column=0,columnspan=2)
        for i in range(len(option1)):
            tk.Radiobutton(win2,text=option1[i],value=option1[i],variable=var1,command=lambda:insert_order(var1.get())).grid(row=i+1,column=0,columnspan=2)
    elif(option.get()==word[1]):
        win2=tk.Tk()
        win2.geometry("200x200")
        var2=tk.StringVar()
        tk.Label(win2,text="which one do you want??").grid(row=0,column=0,columnspan=2)
        for i in range(len(option2)):
            tk.Radiobutton(win2,text=option2[i],value=option2[i],variable=var1,command=lambda:insert_order(var1.get())).grid(row=i+1,column=0,columnspan=2)
    elif(option.get()==word[2]):
        win2=tk.Tk()
        win2.geometry("200x200")
        var3=tk.StringVar()
        tk.Label(win2,text="which one do you want??").grid(row=0,column=0,columnspan=2)
        for i in range(len(option3)):
            tk.Radiobutton(win2,text=option3[i],value=option3[i],variable=var1,command=lambda:insert_order(var1.get())).grid(row=i+1,column=0,columnspan=2)
    else:
        tk.Label(win2,text="未點餐")
win=tk.Tk()
option1=["beef","pork"]
option2=["black tea","milk tea"]
option3=["normal","bacon"]
win.title("order")
text=tk.Text(win)
text.grid(row=4,column=0,columnspan=3)
win.geometry("200x200")
word=["hamburger","drink","noodles"]
option=tk.StringVar()
option.set("")
L1=tk.Label(win,text="which type do you wnat?")
L1.grid(row=0,column=0,columnspan=3)
for i in range(len(word)):
    tk.Radiobutton(win,text=word[i],value=word[i],variable=option,command=reason).grid(row=1,column=i)
tk.Button(win,text="show",command=show).grid(row=3,column=0,columnspan=3)
win.mainloop()
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
海綿寶寶
iT邦大神 1 級 ‧ 2022-03-26 13:36:19

別的我不知道
剛剛測試的結果錯在這一列
tk.Button(win,text="show",command=show).grid(row=3,column=0,columnspan=3)
其中的 command=show 的 show 沒有定義(應該有一個 def 函式)

我要發表回答

立即登入回答