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

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

项目:oil    作者:oilshell    | 项目源码 | 文件源码
def create(self, **kwargs):
        return ttk.Radiobutton(self.root, **kwargs)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def create(self, **kwargs):
        return ttk.Radiobutton(self.root, **kwargs)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
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']))
项目:Enrich2    作者:FowlerLab    | 项目源码 | 文件源码
def body(self, master, row, columns=DEFAULT_COLUMNS, **kwargs):
        self.rb_fastq = ttk.Radiobutton(master, text="FASTQ File Mode",
                                        variable=self.mode, value="FASTQ",
                                        command=self.fastq_mode)
        self.rb_fastq.grid(row=row, column=0, columnspan=columns, sticky="ew")
        self.rb_counts = ttk.Radiobutton(master, text="Count File Mode",
                                         variable=self.mode, value="Counts",
                                         command=self.counts_mode)
        self.rb_counts.grid(row=row + 1, column=0, columnspan=columns,
                            sticky="ew")
        return 2
项目:Enrich2    作者:FowlerLab    | 项目源码 | 文件源码
def body(self, master):
        message = ttk.Label(master, text="SeqLib type:")
        message.grid(column=0, row=0)

        for i, k in enumerate(seqlib_label_text.keys()):
            rb = ttk.Radiobutton(master, text=seqlib_label_text[k],
                                 variable=self.element_tkstring, value=k)
            rb.grid(column=0, row=(i + 1), sticky="w")
            if i == 0:
                rb.invoke()
项目:Enrich2    作者:FowlerLab    | 项目源码 | 文件源码
def body(self, master):
        row_no = self.name_tk.body(master, 0)
        row_no += self.output_directory_tk.body(master, row_no)

        element_types = ttk.Frame(master, padding=(3, 3, 12, 12))
        element_types.grid(column=0, row=row_no, sticky="nsew", columnspan=DEFAULT_COLUMNS)

        message = ttk.Label(element_types, text="Root object type:")
        message.grid(column=0, row=0)

        label = ttk.Label(element_types, text="Experiment")
        label.grid(column=0, row=1, sticky="w")
        rb = ttk.Radiobutton(element_types, text="Experiment", variable=self.element_tkstring, value="Experiment")
        rb.grid(column=0, row=2, sticky="w")
        rb.invoke()

        label = ttk.Label(element_types, text="Selection")
        label.grid(column=0, row=3, sticky="w")
        rb = ttk.Radiobutton(element_types, text="Selection", variable=self.element_tkstring, value="Selection")
        rb.grid(column=0, row=4, sticky="w")

        label = ttk.Label(element_types, text="SeqLib")
        label.grid(column=0, row=5, sticky="w")
        for i, k in enumerate(seqlib_label_text.keys()):
            rb = ttk.Radiobutton(element_types, text=seqlib_label_text[k], variable=self.element_tkstring, value=k)
            rb.grid(column=0, row=(i + 6), sticky="w")
项目:oil    作者:oilshell    | 项目源码 | 文件源码
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']))
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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']))