Python Forum
Function assigned at a button in tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function assigned at a button in tkinter
#8
I'm glad you got that working-ish.

There's a problem with responsibilities here. When the fold button is pressed, the row with the player's cards and the button needs to be removed from the presentation. So, the GUI needs to know what to present. However, the player does not need to know what's presented; the player only needs to know that it folded.

This is the Single Responsibility Principle. As Uncle Bob puts it: "A class should have one and only one reason to change." The GUI should change when a change needs to be made to the GUI but the Player should remain unchanged in that case.

If we separate the front-end presentation and the back-end data flow, we can likely clear up the problem.

class Player:
    self.folded = False
    
    def fold(self):
        self.folded = True

class Presentation:
    def player_folds(self, index, player): # index is for removing the correct row of data
        player.fold()
        ...hide or forget the presented data...
When a new hand is dealt, the Presentation will need new information from the players. I recommend the players contain and manage their information and have a method for providing that to a caller.
Reply


Messages In This Thread
RE: Function assigned at a button in tkinter - by stullis - Oct-05-2019, 07:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to open a popup window in tkinter with entry,label and button lunacy90 1 956 Sep-01-2023, 12:07 AM
Last Post: lunacy90
  Tkinter button images not showing up lunacy90 7 1,682 Aug-31-2023, 06:39 PM
Last Post: deanhystad
Bug tkinter.TclError: bad window path name "!button" V1ber 2 854 Aug-14-2023, 02:46 PM
Last Post: V1ber
  Closing Threads and the chrome window it spawned from Tkinter close button law 0 1,754 Jan-08-2022, 12:13 PM
Last Post: law
  tkinter auto press button kucingkembar 2 3,254 Dec-24-2021, 01:23 PM
Last Post: kucingkembar
  How to assigned value to each different binary in python... ZYSIA 2 2,084 Jul-12-2021, 11:01 AM
Last Post: Gribouillis
  Partial using Tkinter function chesschaser 10 6,913 Jul-03-2020, 03:57 PM
Last Post: chesschaser
  Problem using a button with tkinter SmukasPlays 6 3,389 Jul-02-2020, 08:06 PM
Last Post: SmukasPlays
  Use a button in Tkinter to run a Python function Pedroski55 4 3,344 Jun-28-2020, 05:02 AM
Last Post: ndc85430
  assigned variable fails to show up Skaperen 4 2,405 May-27-2019, 10:48 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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