Python tkinter.ttk 模块,Radiobutton() 实例源码

我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用tkinter.ttk.Radiobutton()

项目:Spectroscope    作者:magin67    | 项目源码 | 文件源码
def SetNumPlotsWidgets(self, rowControl):
        ## ?????????? ???????? (1, 4, 9)
        def SetNumPlots():
            self.shSpectr.NumPlots = NumPlots.get()
            self.scIndex.configure(to=self.toIndex(), value=int(self.shSpectr.iSpectr/self.shSpectr.NumPlots))
            self.SetIndexLabel()
            self.shSpectr.SetPlots()
            self.shSpectr.ShowSp()
            self.SetIndexLabel()

        self.AddLabel(rowControl, "Num of plots      ", colsp=1)

        NumPlots = tk.IntVar(self.frControl)
        NumPlots.set(self.shSpectr.NumPlots)
        self.NumPlots1 = ttk.Radiobutton(self.frControl, text="1", variable=NumPlots, value=1, command=SetNumPlots)
        self.NumPlots2 = ttk.Radiobutton(self.frControl, text="4", variable=NumPlots, value=4, command=SetNumPlots)
        self.NumPlots4 = ttk.Radiobutton(self.frControl, text="9", variable=NumPlots, value=9, command=SetNumPlots)

        PlaceWidget(self.NumPlots1, rowControl, col=1, stick='w')
        PlaceWidget(self.NumPlots2, rowControl, col=1, stick='n')
        rowControl = PlaceWidget(self.NumPlots4, rowControl, col=1, stick='e')

        return self.AddLabel(rowControl)
        #return rowControl
项目:Craft-Clash    作者:Derpyface-Development-Co    | 项目源码 | 文件源码
def create(self, **kwargs):
        return ttk.Radiobutton(self.root, **kwargs)
项目:Craft-Clash    作者:Derpyface-Development-Co    | 项目源码 | 文件源码
def test_invoke(self):
        success = []
        def cb_test():
            success.append(1)
            return "cb test called"

        myvar = tkinter.IntVar(self.root)
        cbtn = ttk.Radiobutton(self.root, command=cb_test,
                               variable=myvar, value=0)
        cbtn2 = ttk.Radiobutton(self.root, command=cb_test,
                                variable=myvar, value=1)

        if self.wantobjects:
            conv = lambda x: x
        else:
            conv = int

        res = cbtn.invoke()
        self.assertEqual(res, "cb test called")
        self.assertEqual(conv(cbtn['value']), myvar.get())
        self.assertEqual(myvar.get(),
            conv(cbtn.tk.globalgetvar(cbtn['variable'])))
        self.assertTrue(success)

        cbtn2['command'] = ''
        res = cbtn2.invoke()
        self.assertEqual(str(res), '')
        self.assertLessEqual(len(success), 1)
        self.assertEqual(conv(cbtn2['value']), myvar.get())
        self.assertEqual(myvar.get(),
            conv(cbtn.tk.globalgetvar(cbtn['variable'])))

        self.assertEqual(str(cbtn['variable']), str(cbtn2['variable']))
项目:Craft-Clash    作者:Derpyface-Development-Co    | 项目源码 | 文件源码
def create(self, **kwargs):
        return ttk.Radiobutton(self.root, **kwargs)
项目:Craft-Clash    作者:Derpyface-Development-Co    | 项目源码 | 文件源码
def test_invoke(self):
        success = []
        def cb_test():
            success.append(1)
            return "cb test called"

        myvar = tkinter.IntVar(self.root)
        cbtn = ttk.Radiobutton(self.root, command=cb_test,
                               variable=myvar, value=0)
        cbtn2 = ttk.Radiobutton(self.root, command=cb_test,
                                variable=myvar, value=1)

        if self.wantobjects:
            conv = lambda x: x
        else:
            conv = int

        res = cbtn.invoke()
        self.assertEqual(res, "cb test called")
        self.assertEqual(conv(cbtn['value']), myvar.get())
        self.assertEqual(myvar.get(),
            conv(cbtn.tk.globalgetvar(cbtn['variable'])))
        self.assertTrue(success)

        cbtn2['command'] = ''
        res = cbtn2.invoke()
        self.assertEqual(str(res), '')
        self.assertLessEqual(len(success), 1)
        self.assertEqual(conv(cbtn2['value']), myvar.get())
        self.assertEqual(myvar.get(),
            conv(cbtn.tk.globalgetvar(cbtn['variable'])))

        self.assertEqual(str(cbtn['variable']), str(cbtn2['variable']))
项目:pkinter    作者:DeflatedPickle    | 项目源码 | 文件源码
def add_radiobutton(self, text="", image="", variable=None, value=None, command=None, side="left"):
        """Adds a RadioButton to the Toolbar."""
        widget = ttk.Radiobutton(self, text=text, image=image, variable=variable, value=value, command=command, style="Toolbutton")
        widget.pack(side=side)

        return widget
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_invoke(self):
        success = []
        def cb_test():
            success.append(1)
            return "cb test called"

        myvar = tkinter.IntVar()
        cbtn = ttk.Radiobutton(command=cb_test, variable=myvar, value=0)
        cbtn2 = ttk.Radiobutton(command=cb_test, variable=myvar, value=1)

        res = cbtn.invoke()
        self.assertEqual(res, "cb test called")
        self.assertEqual(cbtn['value'], myvar.get())
        self.assertEqual(myvar.get(),
            cbtn.tk.globalgetvar(cbtn['variable']))
        self.assertTrue(success)

        cbtn2['command'] = ''
        res = cbtn2.invoke()
        self.assertEqual(res, '')
        self.assertFalse(len(success) > 1)
        self.assertEqual(cbtn2['value'], myvar.get())
        self.assertEqual(myvar.get(),
            cbtn.tk.globalgetvar(cbtn['variable']))

        self.assertEqual(str(cbtn['variable']), str(cbtn2['variable']))
项目:chronophore    作者:mesbahamin    | 项目源码 | 文件源码
def body(self, master):
        """Create dialog body. Return widget that should have initial
        focus.

        Inherited from tkinter.simpledialog.Dialog
        """
        self.frame = ttk.Frame(master, padding=(5, 5, 10, 10))

        self.lbl_message = ttk.Label(
            self.frame,
            text='Select User Type: ',
        )
        self.rb_student = ttk.Radiobutton(
            self.frame,
            text='Student',
            variable=self.rb_choice,
            value='student',
        )
        self.rb_tutor = ttk.Radiobutton(
            self.frame,
            text='Tutor',
            variable=self.rb_choice,
            value='tutor',
        )
        self.btn_ok = ttk.Button(
            self.frame,
            text='OK',
            command=self.ok,
        )
        self.btn_cancel = ttk.Button(
            self.frame,
            text='Cancel',
            command=self.cancel,
        )
        # assemble grid
        self.frame.grid(column=0, row=0, sticky=(N, S, E, W))
        self.lbl_message.grid(column=0, row=0, columnspan=2, sticky=(W, E))
        self.rb_student.grid(column=0, row=1, columnspan=2, sticky=W)
        self.rb_tutor.grid(column=0, row=2, columnspan=2, sticky=W)
        self.btn_ok.grid(column=0, row=3)
        self.btn_cancel.grid(column=1, row=3)

        # key bindings
        self.bind('<Return>', self.ok)
        self.bind('<KP_Enter>', self.ok)
        self.bind('<Escape>', self.cancel)

        self.rb_tutor.invoke()

        return self.btn_ok
项目:jjal_downloader    作者:tucuprum    | 项目源码 | 文件源码
def BatchAdd(): #?? ?? ??
    def selectBatch(): #?? ?? ?? ?? ??
        ans = batchChoice.get()
        if ans == 'g':
            GallBatch()
        #elif ans == 'i': #????? ?? ???? ?? ???? (??? AnalyzePage?? ???)
        #    InstaBatch()
        # elif ans == 't': #??? ?? ???? ?? ????
        #     TwitterBatch()
        elif ans == 'b':
            TistoryBatch()
        elif ans == 'p':
            NaverPostBatch()
        batchAddRoot.destroy()

    batchAddRoot = Toplevel()
    batchChoice = StringVar()
    batchChoice.set('g')
    radioTexts = [['?????? ??? (??? ??)','g'],
        #['?????','i'],
        ['???? ???','b'],
        ['??? ???','p']
    ]

    ttk.Label(batchAddRoot, text='?? ??? ???? ??????.').pack(padx=GUI_PARAM['LabelPadX'],pady=GUI_PARAM['LabelPadY'])

    for text, code in radioTexts:
        ttk.Radiobutton(batchAddRoot, text=text, variable = batchChoice, value = code).pack(padx=GUI_PARAM['LabelPadX'],anchor=W)

    ttk.Button(batchAddRoot,text='??',command=selectBatch).pack(padx=GUI_PARAM['ButtonPadX'],pady=GUI_PARAM['ButtonPadY'])



#### ?? ?? ?? (tree) ?? ?? ####
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def create(self, **kwargs):
        return ttk.Radiobutton(self.root, **kwargs)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_invoke(self):
        success = []
        def cb_test():
            success.append(1)
            return "cb test called"

        myvar = tkinter.IntVar(self.root)
        cbtn = ttk.Radiobutton(self.root, command=cb_test,
                               variable=myvar, value=0)
        cbtn2 = ttk.Radiobutton(self.root, command=cb_test,
                                variable=myvar, value=1)

        if self.wantobjects:
            conv = lambda x: x
        else:
            conv = int

        res = cbtn.invoke()
        self.assertEqual(res, "cb test called")
        self.assertEqual(conv(cbtn['value']), myvar.get())
        self.assertEqual(myvar.get(),
            conv(cbtn.tk.globalgetvar(cbtn['variable'])))
        self.assertTrue(success)

        cbtn2['command'] = ''
        res = cbtn2.invoke()
        self.assertEqual(str(res), '')
        self.assertLessEqual(len(success), 1)
        self.assertEqual(conv(cbtn2['value']), myvar.get())
        self.assertEqual(myvar.get(),
            conv(cbtn.tk.globalgetvar(cbtn['variable'])))

        self.assertEqual(str(cbtn['variable']), str(cbtn2['variable']))
项目:quill    作者:DeflatedPickle    | 项目源码 | 文件源码
def insert_tk_radiobutton(self, index: int or str="end", *args, **kwargs):
        """Insert a tk.Radiobutton into the game."""
        widget = tk.Radiobutton(self.text, **kwargs)
        self.text.window_create(index, window=widget)

        return widget
项目:quill    作者:DeflatedPickle    | 项目源码 | 文件源码
def insert_ttk_radiobutton(self, command=None, value: int=None, variable: tk.IntVar=None, index: int or str="end", *args, **kwargs):
        """Insert a ttk.Radiobutton into the game."""
        widget = ttk.Radiobutton(self.text, command=command, value=value, variable=variable, **kwargs)
        self.text.window_create(index, window=widget)

        return widget
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def create(self, **kwargs):
        return ttk.Radiobutton(self.root, **kwargs)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_invoke(self):
        success = []
        def cb_test():
            success.append(1)
            return "cb test called"

        myvar = tkinter.IntVar(self.root)
        cbtn = ttk.Radiobutton(self.root, command=cb_test,
                               variable=myvar, value=0)
        cbtn2 = ttk.Radiobutton(self.root, command=cb_test,
                                variable=myvar, value=1)

        if self.wantobjects:
            conv = lambda x: x
        else:
            conv = int

        res = cbtn.invoke()
        self.assertEqual(res, "cb test called")
        self.assertEqual(conv(cbtn['value']), myvar.get())
        self.assertEqual(myvar.get(),
            conv(cbtn.tk.globalgetvar(cbtn['variable'])))
        self.assertTrue(success)

        cbtn2['command'] = ''
        res = cbtn2.invoke()
        self.assertEqual(str(res), '')
        self.assertLessEqual(len(success), 1)
        self.assertEqual(conv(cbtn2['value']), myvar.get())
        self.assertEqual(myvar.get(),
            conv(cbtn.tk.globalgetvar(cbtn['variable'])))

        self.assertEqual(str(cbtn['variable']), str(cbtn2['variable']))
项目:synthesizer    作者:irmen    | 项目源码 | 文件源码
def __init__(self, app, master):
        super().__init__(master, text="Search song", padding=4)
        self.app = app
        self.search_text = tk.StringVar()
        self.filter_choice = tk.StringVar(value="title")
        bf = ttk.Frame(self)
        ttk.Label(bf, text="Search for:").pack()
        e = ttk.Entry(bf, textvariable=self.search_text)
        e.bind("<Return>", self.do_search)
        e.bind("<KeyRelease>", self.on_key_up)
        self.search_job = None
        e.pack()
        ttk.Radiobutton(bf, text="title", value="title", variable=self.filter_choice, width=10).pack()
        ttk.Radiobutton(bf, text="artist", value="artist", variable=self.filter_choice, width=10).pack()
        ttk.Radiobutton(bf, text="album", value="album", variable=self.filter_choice, width=10).pack()
        ttk.Radiobutton(bf, text="year", value="year", variable=self.filter_choice, width=10).pack()
        ttk.Radiobutton(bf, text="genre", value="genre", variable=self.filter_choice, width=10).pack()
        ttk.Button(bf, text="Search", command=self.do_search).pack()
        ttk.Button(bf, text="Add all selected", command=self.do_add_selected).pack()
        bf.pack(side=tk.LEFT)
        sf = ttk.Frame(self)
        cols = [("title", 320), ("artist", 200), ("album", 200), ("year", 50), ("genre", 120), ("length", 60)]
        self.resultTreeView = ttk.Treeview(sf, columns=[col for col, _ in cols], height=11, show="headings")
        vsb = ttk.Scrollbar(orient="vertical", command=self.resultTreeView.yview)
        self.resultTreeView.configure(yscrollcommand=vsb.set)
        self.resultTreeView.grid(column=1, row=0, sticky=tk.NSEW, in_=sf)
        vsb.grid(column=0, row=0, sticky=tk.NS, in_=sf)
        for col, colwidth in cols:
            self.resultTreeView.heading(col, text=col.title(), command=lambda c=col: self.sortby(self.resultTreeView, c, 0))
            self.resultTreeView.column(col, width=colwidth)
        self.resultTreeView.bind("<Double-1>", self.on_doubleclick)
        sf.grid_columnconfigure(0, weight=1)
        sf.grid_rowconfigure(0, weight=1)
        sf.pack(side=tk.LEFT, padx=4)
项目:LadderiLogical    作者:mikadam    | 项目源码 | 文件源码
def __init__(self, *args):

        super().__init__(*args)


        self.conector_checks[0].set(0)
        self.conector_checks[1].set(1)
        self.conector_checks[2].set(0)
        self.conector_checks[3].set(2)

        vcmd = (self.root.register(self.validate), '%P', '%s','%S', '%d')


        self.timer_mode = tk.IntVar()
        self.timer_mode.set(1)

        ttk.Radiobutton(master=self.frame, text="Hold", variable=self.timer_mode, value=1).pack()
        ttk.Radiobutton(master=self.frame, text="Delay Monostable", variable=self.timer_mode, value=2).pack()
        # ttk.Radiobutton(master=self.frame, text="Manaul", variable=self.timer_mode, value=3).pack()



        self.time_dalay=ttk.Entry(master=self.frame,width=10,validate="key",validatecommand=vcmd)
        self.time_dalay.pack()
        self.time_dalay.insert(0,"1000")

        self.time=time()

        self.top_box=self.board.canvas.create_rectangle((self.x+0.3)*self.board.tile_size,(self.y+0.7)*self.board.tile_size,(self.x+0.7)*self.board.tile_size,(self.y)*self.board.tile_size,fill="",outline="")
        self.bottom_box=self.board.canvas.create_rectangle((self.x+0.3)*self.board.tile_size,(self.y+0.3)*self.board.tile_size,(self.x+0.7)*self.board.tile_size,(self.y+1)*self.board.tile_size,fill="",outline="")
        self.left_box=self.board.canvas.create_rectangle((self.x+0.7)*self.board.tile_size,(self.y+0.7)*self.board.tile_size,(self.x)*self.board.tile_size,(self.y+0.3)*self.board.tile_size,fill="#FF0000",outline="")
        self.right_box=self.board.canvas.create_rectangle((self.x+0.3)*self.board.tile_size,(self.y+0.3)*self.board.tile_size,(self.x+1)*self.board.tile_size,(self.y+0.7)*self.board.tile_size,fill="#FF0000",outline="")

        self.timer_box=self.board.canvas.create_rectangle((self.x+0.2)*self.board.tile_size,(self.y+0.2)*self.board.tile_size,(self.x+0.8)*self.board.tile_size,(self.y+0.8)*self.board.tile_size,fill="#888888",outline="#EEEEEE") 
        self.timer_shield=self.board.canvas.create_oval((self.x+0.3)*self.board.tile_size,(self.y+0.3)*self.board.tile_size,(self.x+0.7)*self.board.tile_size,(self.y+0.7)*self.board.tile_size,fill="#DDDDDD",outline="#EEEEEE") 
        self.timer_tick=self.board.canvas.create_line((self.x+0.5)*self.board.tile_size,(self.y+0.3)*self.board.tile_size,(self.x+0.5)*self.board.tile_size,(self.y+0.5)*self.board.tile_size,fill="#111111") 
        self.timer_tock=self.board.canvas.create_line((self.x+0.6)*self.board.tile_size,(self.y+0.5)*self.board.tile_size,(self.x+0.5)*self.board.tile_size,(self.y+0.5)*self.board.tile_size,fill="#111111") 


        self.input_update=self.input_update_1

        self.time_to=1000
        self.state=0
        self.prev=0
        self.edge=0
        self.latch=0

        self.graphic_conectors=[self.top_box,self.right_box,self.bottom_box,self.left_box]

        self.graphics=[self.timer_box,self.timer_shield,self.timer_tick,self.timer_tock,
                        self.top_box,self.bottom_box,self.left_box,self.right_box]