Tkinter单选按钮默认未选中

时间:2018-11-06 22:35:06

标签: python tkinter

我很茫然。即使我遵循了有关单选按钮的各种教程,默认情况下也不会检查我的单选按钮。不确定我在做什么错,我将默认单选按钮设置为“假”按钮。

这是我的代码:

import tkinter as tk
import tkinter.ttk as ttk
from tkinter.colorchooser import *


class ExampleView(tk.Frame):
    def __init__(self, *args, **kwargs):
        tk.Frame.__init__(self, *args, **kwargs)

        """ create StringVars for our shape fill radio button group """
        shape_fill_status = tk.StringVar()

        """ create radio button group for turning off shape fill """
        shape_fill_frame = tk.Frame(self)
        shape_fill_label = tk.Label(shape_fill_frame, text="Fill Shape: ",  anchor="w")
        shape_fill_label.pack(side=tk.LEFT, padx = 10)
        shape_fill_false = tk.Radiobutton(shape_fill_frame, text = "False", variable = shape_fill_status, value = 0)

        shape_fill_true = tk.Radiobutton(shape_fill_frame, text = "True", variable = shape_fill_status, value = 1)
        shape_fill_status.set(0)
        shape_fill_false.pack(side=tk.LEFT, padx = 10)
        shape_fill_true.pack(side=tk.LEFT, padx = 10)
        shape_fill_frame.grid(row=0, column=0, stick="w")

        self.grid_columnconfigure(0, weight=1)

if __name__ == "__main__":
    root = tk.Tk()
    view = ExampleView(root)
    view.pack(side="top", fill="both", expand=True)
    root.wm_geometry("400x200")
    root.mainloop()

这是我的tkinter小部件的样子:

screenshot of widget

1 个答案:

答案 0 :(得分:2)

您正在使用局部变量来存储import numpy as np class myarray(np.ndarray): def __getitem__(self, index): if isinstance(index, tuple): index = index[0] + 1, else: index += 1 return super(myarray, self).__getitem__(index) my_k = np.linspace(0, 10, 10).view(myarray) k = np.linspace(0, 10, 10).view(np.ndarray) print(my_k) print(k) StringVar完成后,变量将被销毁。

__init__更改为shape_fill_status