Python Forum
How do you make functions that take a variable that is not defined?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do you make functions that take a variable that is not defined?
#6
(Sep-24-2018, 09:42 AM)magic Wrote: That's not default argument. I know what default argument is.
Those variables were never defined but passed down into the function in capital letters.
This how Tkinter dos it,you should mention where code comes from to get better answers.
>>> from tkinter import LEFT, TOP, X, FLAT, RAISED
>>> TOP
'top'
>>> LEFT
'left'
>>> FLAT
'flat'
>>> X
'x'
So toolbar.pack(side=TOP, fill=X) is the same as toolbar.pack(side='top', fill='x')
So it could work fine as default argument to a function.

With toolbar.pack() they are passed in as key word arguments(**kwargs).
If look at method parameters in Tkinter code.
def pack_configure(self, cnf={}, **kw):
Example:
>>> def my_function(**kw):
...     print(kwargs)  
...     
>>> my_function(a=123, b="hello")
{'a': 123, 'b': 'hello'}
Reply


Messages In This Thread
RE: How do you make functions that take a variable that is not defined? - by snippsat - Sep-24-2018, 01:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Variable not defined even though it is CoderMerv 3 479 Mar-28-2024, 02:13 PM
Last Post: Larz60+
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 750 Nov-23-2023, 02:53 PM
Last Post: rob101
  Calling functions by making part of their name with variable crouzilles 4 1,011 Nov-02-2023, 12:25 PM
Last Post: noisefloor
  Printing the variable from defined function jws 7 1,644 Sep-03-2023, 03:22 PM
Last Post: deanhystad
  Whys is asterisk and random variable necessary in these functions? rrowhe4d 5 1,683 Aug-05-2022, 07:53 AM
Last Post: Gribouillis
  [variable] is not defined error arises despite variable being defined TheTypicalDoge 4 2,395 Apr-05-2022, 04:55 AM
Last Post: deanhystad
  Why built in functions are defined as class? quazirfan 5 3,042 Oct-23-2021, 01:20 PM
Last Post: Gribouillis
  How to make general functions for ecuations Mondata 6 2,982 Mar-11-2021, 09:15 PM
Last Post: Mondata
  Running scripts and location of saved interpreted user-defined classes and functions leodavinci1990 3 2,680 Aug-25-2020, 03:43 AM
Last Post: micseydel
  Function will not return variable that I think is defined Oldman45 6 3,721 Aug-18-2020, 08:50 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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