Python Forum
Multi windows in tkinter buttons not responding correctly
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multi windows in tkinter buttons not responding correctly
#11
... stand by, still reading through the 'imports' Big Grin
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#12
(Jun-30-2017, 06:49 PM)nilamo Wrote:
(Jun-30-2017, 06:07 PM)Barrowman Wrote: I haven't been using classes myself but looking at this and other ( working ) examples of code I think you need a change:

[snip]

to this:
 class [email protected]
   def __init__(self):

       if (bus1.read_pin(15) == 1):
          bus1.write_pin(15, 0)
          Mainfloor.toggleButton1["text"] = ("Fireplace On")
        
       else:Mainfloor
               bus1.write_pin(15, 1)
               Mainfloor.toggleButton1["text"] = ("Fireplace Off")
Of course I may be wrong as I usually am  Confused

Quote:
 class [email protected]
The class keyword starts a definition block, and like all other block structures (def, if, for), it uses a colon at the end of the line, not an @.

Quote:
Mainfloor.toggleButton1["text"] = ("Fireplace On")
The Mainfloor class, itself, does not have a toggleButton1, but it's instances do.  So that would throw an error as you're trying to modify something that doesn't exist.

Nice try, though :)

I have no idea where the @ came from! I copied his code and then pasted his code as was and then again but modified it. I hadn't noticed that somehow the : had changed to @
Ah well I said I'm usually wrong.
Reply
#13
(Jun-30-2017, 06:57 PM)nilamo Wrote: toggleButton1 only exists in the MainFloor class.  You're trying to change it from within the Fireplace class.  A nice way to handle this would be using events or signals (something frequently done in game programming, and is how something like the physics code will do most of it's communication).  But that'd be a whole lot of changes.

You currently pass each object a controller object, but the Fireplace doesn't keep track of it.  If you do, then you can crawl into the controller and manipulate it's frames to get to the MainFloor to do what you're trying to do.  So, Fireplace would then look like this:

Thanks for the information I will have to do some research on events. I implemented the code changes you posted and I received this as an error:


Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.4/tkinter/__init__.py", line 1536, in __call__
return self.func(*args)
TypeError: __init__() missing 1 required positional argument: 'controller'
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.4/tkinter/__init__.py", line 1536, in __call__
return self.func(*args)
TypeError: __init__() missing 1 required positional argument: 'controller'

(Jun-30-2017, 07:00 PM)sparkz_alot Wrote: ... stand by, still reading through the 'imports'  Big Grin

Yes I know there is a lot of imports and I'm sure there is probably duplicates of the same thing. Like I mentioned I am very new to programming. Once I get a part of it working by itself I would copy and paste them together, adding new and getting rid of old. Going through the list of imports to find out which ones are being used hasn't been on my priority list.
Reply
#14
(Jun-28-2017, 10:39 PM)curtjohn86 Wrote:
frame = F(parent=container, controller=self)

You're constructing each window/frame with two parameters, parent, and controller.  So you can either change Fireplace to have both (def __init__(self, parent, controller):), or you can change Fireplace to use keyworded parameters (def __init__(self, controller=None):).  Either should fix the issue.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGTK] How to center text on multi-line buttons? Lomax 3 1,541 Jan-23-2021, 03:23 PM
Last Post: Lomax
  Dual Tkinter windows and shells Astrikor 6 1,326 Sep-03-2020, 10:09 PM
Last Post: Astrikor
  [Tkinter] How to compare two variables correctly in tkinter scratchmyhead 2 1,525 May-10-2020, 08:04 PM
Last Post: scratchmyhead
  PyQt GUI not responding samuelbachorik 0 2,047 Apr-25-2020, 08:08 PM
Last Post: samuelbachorik
  TkInter Binding Buttons ifigazsi 5 1,261 Apr-06-2020, 08:30 AM
Last Post: ifigazsi
  Tkinter scaling windows conten to or with its size not working Detzi 5 1,989 Jan-12-2020, 12:42 PM
Last Post: Detzi
  Issue on tkinter with buttons Reldaing 1 1,402 Jan-07-2020, 08:21 AM
Last Post: berckut72
  Need tkinter help with clicking buttons pythonprogrammer 2 1,121 Jan-03-2020, 04:43 AM
Last Post: joe_momma
  How to close one of the windows in Tkinter scratchmyhead 3 2,555 Dec-21-2019, 06:48 PM
Last Post: pashaliski
  Tkinter Buttons action d3fi 1 948 Nov-20-2019, 09:16 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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