TTk单选按钮

时间:2019-03-27 09:55:41

标签: python tkinter

我定义了一个“示例”类,其中有两个单选按钮,当我按“ bu1”时,spangender不会取任何值。请帮帮我

SELECT s.*
FROM Stores s
WHERE EXISTS (SELECT 1 FROM Stores s1 WHERE s1.Industry = s.Industry AND s1.Name <> s.Name);

1 个答案:

答案 0 :(得分:0)

使用Toplevel而不是创建另一个Tk实例。

from tkinter import *
from tkinter import ttk

class exemple():

     def like(self):
            win = Toplevel()
            style = ttk.Style()
            style.theme_use('classic')
            spangender = StringVar()
            rb1 = ttk.Radiobutton(win, text='male', variable=spangender, value='male')
            rb1.grid(column=0, row=0)
            rb2 = ttk.Radiobutton(win, text='female', variable=spangender, value='female')
            rb2.grid(column=1, row=0)
            bu1 = ttk.Button(win, text='ok', command=lambda: get())
            bu1.grid(column=2, row=1)
            def get():
                print(spangender.get())

root = Tk()
style = ttk.Style()
style.theme_use('classic')
def get():
    ab = exemple()
    ab.like()
bu1 = ttk.Button(root, text='ok', command=lambda: get())
bu1.grid(column=2, row=1)
root.mainloop()