Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Global not working why?
#11
Of course you cannot get the scratches. A GUI program is event driven. You are trying to write it as if things happen sequentially.
        get_scratches(horses_name)  # Draws the scratched form
        print(scratched_list)  # There are no scratches at this time

The code above expects there to be information in the scratches form as soon as it is created. Obviously this is not going to happen. What your code needs to do is present the form to the user and end. The user will then enter the scratched information and press a button indicating the form is complete. The button press will call a function that uses the scratched information.

A GUI program is not a list of steps to complete. You cannot write a GUI as Do A, B, C, D in order. A GUI program is list of events and the actions that are performed when these events occur. The user specifies the sequence order using the controls provided by your program. If I am creating a graph in Excel, the program does not force me to load data, select columns, insert line graph, select graph format. Instead the program provides controls that allows me to perform those functions. I can load data and then make a graph, then delete the graph or add more data. I, the user, am in control of when the program does what.

Right now your program has only one event: Scratch List Done Button Pressed. The action associated with that event will be all the code that currently resides in def load_track_to_Handi() below the point where the call to get_scratches(horses_name). I would take that code and add it to complete_form().
Reply
#12
I will stop and look over my code. This is how it is laid out and should work to the point where I am now.

Program loads and presents a GUI.
1.On that there is a text box, user enters race date to handicap.
2. User clicks a load race files button.
3. Program goes to race folder and reads the csv file and selects the fields needed and then writes that to a file.
4. user then selects a race track and clicks on that button. The track name associated with that button loads into variable.
5. User then clicks on a race number button which assigns the associated number to a variable.
6. At that point the program goes to the file and pulls the race data. Def load race to handi
7. In that function the program calls get scratches. A scratch window opens with list of horses in that race.
8. when the scratch window is closed after scratches are done or there are none, def complete form is called. The results of the scratch window is loaded from scratched into scratch_list.

And that is where I am. So everything up to now is all event driven. So in that last def I put a print statement for testing to make sure the state of each horse is recorded. Now I need to be able to access scratched list which I will use as a conditional to see if a horse info is loaded or skipped over.

I know very little about classes and my program logic is weak for sure. I have a complete working program I wrote in another language, but it is slow and limited. That's why I am trying to learn Python. I learn best by working on problems I am very interested in, Horse race handicapping in this case. I will watch some videos on classes and program design. Maybe that will help me.
Reply
#13
Quote:I know very little about classes and my program logic is weak for sure
On this forum:
class basics
Class Intermediate: Inheritance
Class Intermediate: Operator Overloading
Classes [advanced]: Dependent attributes (and Descriptors)
Classes [advanced]: Descriptors (managed attributes)

Also
see: https://realpython.com/python3-object-or...-in-python
Reply
#14
Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Global variables not working hobbyist 9 4,618 Jan-16-2021, 03:17 PM
Last Post: jefsummers
  Global variable does not seem to be global. Columbo 6 3,617 Jul-15-2019, 11:00 PM
Last Post: Columbo

Forum Jump:

User Panel Messages

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