Reputation: 341
I am trying to make my own tkinter widgets.
Right now I am working on custom radiobuttons. The idea is to have each radiobutton to actually be a frame, inside of which is a canvas that is next to a label.
The canvas is the circle that fills when clicked upon, and the label displays the text that indicates what the radiobutton controlls.
I have created a class for such widgets that looks like this..
class Custom_RadioButton(Frame):
def __init__(self, *args):
Frame.__init__(self, *args)
I am having trouble figuring out how to add the label and canvas inside of this frame because it does not really have a name to place anywhere like Label.__init__(self, Framename, *args)
Thanks
Upvotes: 1
Views: 919
Reputation: 36662
You could do something like this:
import tkinter as tk # <-- avoid star imports
class Custom_RadioButton(tk.Frame):
def __init__(self, master, *args, **kwargs):
super().__init__(self, master, *args, **kwargs)
self.canvas = tk.Canvas(self) # place a canvas into self (a Frame)
self.canvas.pack(expand=True, fill=tk.BOTH)
self.label = tk.Label(self.canvas, text='clickme') # place a label in self.canvas
self.canvas.create_oval(.....) # draw a circle on self.canvas
Upvotes: 1