Python Forum
Centering and adding a push button to a grid window, TKinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Centering and adding a push button to a grid window, TKinter
#16
Do you understand the error message now?

You got an error doing this:
label[x]
label is a tkinter Label object. Label objects support indexing, but you provide an attribute name as in label["bg"]. x is an int, not a str. Label objects don't understand indexing using ints. When Python tries to get the object associated with the index/key, it calls this.
return self.tk.call(self._w, 'cget', '-' + key)
Normally key would be a str, like "bg", but in your code it is an int (0). It cannot add 'cget' + 0. When you try to add an int and a str you get a type error.
Error:
TypeError: can only concatenate str (not "int") to str
Reply


Messages In This Thread
RE: Centering and adding a push button to a grid window, TKinter - by deanhystad - May-25-2023, 07:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 599 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  [Tkinter] TKinter Remove Button Frame Nu2Python 8 1,094 Jan-16-2024, 06:44 PM
Last Post: rob101
  tkinter - touchscreen, push the button like click the mouse John64 5 928 Jan-06-2024, 03:45 PM
Last Post: deanhystad
  Tkinter multiple windows in the same window tomro91 1 895 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  [Tkinter] Open tkinter colorchooser at toplevel (so I can select/focus on either window) tabreturn 4 1,968 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  [Tkinter] Background inactivity timer when tkinter window is not active DBox 4 2,976 Apr-16-2022, 04:04 PM
Last Post: DBox
  [Tkinter] Clicking on the button crashes the TK window ODOshmockenberg 1 2,272 Mar-10-2022, 05:18 PM
Last Post: deanhystad
  why my list changes to a string as I move to another window in tkinter? pymn 4 2,611 Feb-17-2022, 07:02 AM
Last Post: pymn
  Can't get tkinter button to change color based on changes in data dford 4 3,472 Feb-13-2022, 01:57 PM
Last Post: dford
  [Tkinter] Tkinter Window Has no Title Bar gw1500se 4 2,890 Nov-07-2021, 05:14 PM
Last Post: gw1500se

Forum Jump:

User Panel Messages

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