Python Forum
[Tkinter] Tkinter Font Color
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Tkinter Font Color
#7
If you use one equal sign, use them on everything.

This can be quite confusing, the following mess shows why:

The actual rule is that:

any required arguments must have values, and order must be preserved if they do not use '='.
If = is used on both, they can be out of order.
but once an equal sign has been used, all remaining required arguments must also have one.

Non required arguments can be in any order if and only if they contain '=' signs.

Non required arguments don't require '=' if all arguments remain in order

An example will make this clearer:

c, d and e are defaulted, so don't have to be supplied
and can be in any order so long as they contain an = sign
a and b are, required and must be in order
>>> def xxx (a, b, c=0, d=1, e=2):
...    print(a)
...    print(b)
...    print(c)
...    print(d)
...    print(e)
The function above requires and a and b at minimum, so:

>>> xxx(a=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: xxx() missing 1 required positional argument: 'b'
creates error because b is required and missing

>>> xxx(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: xxx() missing 1 required positional argument: 'b'
creates error because b is required and missing

>>> xxx(1, b=2)
1
2
0
1
2
>>>
Works because both a and b have been passed

as will:
xxx(1, 2)
but not:
>>> xxx(a=2,3)
  File "<stdin>", line 1
SyntaxError: positional argument follows keyword argument
>>>
because once '=' has been used for o
and the following will work:
>>> xxx(a=2, b=3)
2
3
0
1
2
>>>
>>> xxx(1,2,3, e=7)
1
2
3
1
7
>>>
works because 1,2,3 are in order and e contains =

and finally:
>>> xxx(1,2,c=3,4,e=7)
  File "<stdin>", line 1
SyntaxError: positional argument follows keyword argument
>>> xxx(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: xxx() missing 1 required positional argument: 'b'
does not. Once the first defaulted argument contains an = sign, all that follow also require it

Bottom line is Always use assignment ('=') it will save you grief
Reply


Messages In This Thread
Tkinter Font Color - by notsolowki - Mar-25-2018, 07:22 AM
RE: Tkinter Font Color - by Larz60+ - Mar-25-2018, 08:48 AM
RE: Tkinter Font Color - by notsolowki - Mar-26-2018, 10:14 AM
RE: Tkinter Font Color - by notsolowki - Mar-26-2018, 08:28 AM
RE: Tkinter Font Color - by Larz60+ - Mar-26-2018, 11:21 AM
RE: Tkinter Font Color - by notsolowki - Mar-26-2018, 11:24 AM
RE: Tkinter Font Color - by Larz60+ - Mar-26-2018, 04:09 PM
RE: Tkinter Font Color - by notsolowki - Mar-27-2018, 02:10 AM
RE: Tkinter Font Color - by Larz60+ - Mar-27-2018, 04:34 AM
RE: Tkinter Font Color - by notsolowki - Mar-27-2018, 05:09 AM
RE: Tkinter Font Color - by Larz60+ - Mar-27-2018, 10:52 AM
RE: Tkinter Font Color - by notsolowki - Mar-28-2018, 03:53 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter - How can I change the default Notebook border color? TurboC 5 15,065 May-23-2022, 03:44 PM
Last Post: bigmac
  Can't get tkinter button to change color based on changes in data dford 4 3,574 Feb-13-2022, 01:57 PM
Last Post: dford
  [Tkinter] Trouble changing Font within tkinter frame title AnotherSam 1 4,366 Sep-30-2021, 05:57 PM
Last Post: menator01
Question [Tkinter] Can I set background color for each item in tkinter Combobox? water 1 5,262 Dec-10-2020, 07:48 PM
Last Post: Larz60+
  Tkinter menu font size -method to change tonycat 2 8,031 Oct-11-2020, 02:43 AM
Last Post: tonycat
  tkinter | Button color text on Click Maryan 2 3,510 Oct-09-2020, 08:56 PM
Last Post: Maryan
  [Tkinter] How to Print a list = ['a','b','c'], using tkinter along with a custom font? Pleiades 2 2,467 Sep-15-2020, 03:54 PM
Last Post: Pleiades
  [tkinter] color change for hovering over button teacher 4 8,821 Jul-04-2020, 06:33 AM
Last Post: teacher
  TKINTER - Change font color for night or day Ayckinn 2 4,005 May-24-2020, 09:25 PM
Last Post: Ayckinn
  Tkinter help (color) Florent 2 2,426 Mar-01-2020, 02:59 PM
Last Post: Florent

Forum Jump:

User Panel Messages

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