Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
kwargs question
#3
Thank you for such a rapid response, are the asterisk similar to a C pointer ?

I put a sample into my own code and it worked perfectly but I feel because I am not fully understanding I am just hard coding the values.

Below worked great

class ClassName(Tk.Frame):
	def __init__( self, parent, **options ):
		Tk.Frame.__init__( self, parent, **options ) 
		options = {'bg': 'tan'}
		self.parent=parent
		
		self.canvas=Canvas(self,width=300,height=300,**options)
		self.canvas.grid(row=0,column=0)
In my main class I would like to pass the options when I create the instance of widget_1 and widget_2 from ClassName

class Master_Gui():

	def __init__(self):
		self.root=Tk()
		self.root.title("Widget Control")
		self.root.resizable(False,False)
		self.display_widgets(self.root)

    def display_widgets(self,root):
		self.widget_1=ClassName(self.root) #pass in the bg color ??
		self.widget_1.grid(row=0,column=0)
		self.widget_2=ClassName(self.root) #pass in the bg color ??
		self.widget_2.grid(row=0,column=1)
Sorry if I am slow to catch on but once I see it then it will be there forever.

Jeff
Reply


Messages In This Thread
kwargs question - by Jeff_t - Feb-15-2022, 07:25 PM
RE: kwargs question - by menator01 - Feb-15-2022, 07:45 PM
RE: kwargs question - by Jeff_t - Feb-15-2022, 08:38 PM
RE: kwargs question - by deanhystad - Feb-15-2022, 08:48 PM
RE: kwargs question - by Jeff_t - Feb-15-2022, 09:04 PM
RE: kwargs question - by deanhystad - Feb-15-2022, 09:10 PM
RE: kwargs question - by stevendaprano - Feb-16-2022, 10:59 AM
RE: kwargs question - by snippsat - Feb-16-2022, 03:31 PM
RE: kwargs question - by Jeff_t - Feb-16-2022, 04:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I instantiate a class with **kwargs? palladium 6 7,732 Feb-16-2023, 06:10 PM
Last Post: deanhystad
  Misunderstanding kwargs? Donovan 2 2,315 Aug-04-2020, 08:09 PM
Last Post: Donovan
  **kwargs question DPaul 10 4,516 Apr-01-2020, 07:52 AM
Last Post: buran
  Unpacking dictionary from .xlsx as Kwargs etjkai 5 2,947 Dec-27-2019, 05:31 PM
Last Post: etjkai
  opts vs kwargs Skaperen 4 2,543 Nov-30-2019, 04:57 AM
Last Post: Skaperen
  create dictionary from **kwargs that include tuple bluefrog 2 4,935 Oct-26-2016, 10:24 PM
Last Post: Larz60+
  How do you use *args and **kwargs? Gengar 3 20,002 Sep-20-2016, 04:22 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020