使用radiobuttons中的控制变量时,Tkinter中的AttributeError

时间:2018-06-04 07:26:52

标签: python variables tkinter

我试图获取radiobutton的值并将此int存储到varable中。这是我的第一个tkinter项目,所以我很抱歉我的愚蠢错误...

from tkinter import *
from tkinter import ttk
select = "A"
def begin():
    grand = Tk()
    grand.title("Converter")
    window.destroy()
    frame = Frame(grand)
    option = IntVar()

- > AttributeError:' NoneType'对象没有属性' _root'

    grandlabel = Label(frame, text="Choose the grand").grid(row=0, sticky=N, padx=5)
    grand1 = Radiobutton(frame, text="Speed", variable=option, value=1, command=sel).grid(row=1, sticky=W)
    grand2 = Radiobutton(frame, text="etc", variable=option, value=2, command=sel).grid(row=2, sticky=W)
    submitgrand = Button(frame, text="Ok", command=unit).grid(row=3, sticky=W)
    frame.pack()
    grand.mainloop()

def sel():
    global option
    global select
    select = option.get()
    option = StringVar()

def unit():
    unit = Tk()
    global select
    select = grandchosen
    if (grandchosen == "Speed"):
        Label(unit, text="Test").pack()
    else:
        Label(unit, text="Test2").pack()
    unit.mainloop()

root = Tk()
frame = Frame(root)
welcome = ttk.Label(frame, text="Welcome!").grid(row=0, sticky=N, padx=10, pady=3)
okbutton = Button(frame, text="Ok", width=15, command=begin).grid(row=1, sticky=S, padx=20, pady=30)
frame.pack()
style = ttk.Style()
style.configure("TLabel", foreground="midnight blue", font="Times 19")
root.mainloop()

很高兴得到一些帮助,谢谢!

0 个答案:

没有答案