Python help using tkinter
This is my first attempt at a python app and can't find the answers i need so thought i would post here for some help.
This app will be a replacement for my Unitab prices excel sheet, so far i can import the venues and a bit of info for the day, i have tried a few different methods and the closes i can get is it prints the first venue info and stops, yet if you run this in your ide it prints all the info as i would like it. The print statement doesn't need to be there. Code:
|
Success......always the way, try to solve a problem for a couple days as soon as i post the issue i figure it out.
Code:
|
I have progressed a bit further but having issues with the formatting, if you run this you will notice the results are going in a downward pattern rather than lining up under the headings.
Code:
|
try .strip()
on the entries |
my early morning guess does not work
to make debug easier, change background colours just do a think like MNA_COLOR = "Red" LOC_COLOR = "Blue" and use that in places like your race info then, when you are all filled with joy, change them to what you really want it is a long time since i used tkinter i will see if i can find a better answer for you |
label.grid( row=0,column=0,sticky=w)
|
I will try your background solution, it might let me see what's going on, as for adding the row this seems to stop the loop as it always prints on row 0
|
I solved this by creating a frame and spanning the column, i then just packed everything in from the left then just looped over and did it again.
Setting the colours definitely made a difference as i could see what was happening, now just to set them all back. Code:
|
#sorry for my rushed reply.
#above the for Venue in venues: rowo = 0 for Venue in Venues: #add row=rowo to your .grid( lines #then at the bottom of that loop under Wcondition_label.grid( column=4,sticky=W,row=rowo) rowo += 1 #that will increment the row number #you need row=rowo or whatever you choose to call it alongside the column=n |
I will also try this as it may be useful moving forward with this project.
|
i hope this gets pasted properly
####### add row number rowo = 0 for Venue in Venues: Rtype = Venue["raceType"] Mname = Venue["meetingName"] Location = Venue["location"] ###### weather and track condition might not be there if "weatherCondition" in Venue: Wcondition = Venue["weatherCondition"] else: Wcondition = "BLEEK" if "trackCondition" in Venue: Tcondition = Venue["trackCondition"] else: Tcondition = "TkCoon" states = ("VIC","NSW","QLD","SA","WA","TAS","ACT") if Rtype == "R" and Location in states: #Race Info Mname_label = Label(Rinfo, text=Mname, font=("bold", 12), width=15, anchor=W, bg="Red") Mname_label.grid(column=0, sticky=W,row=rowo) Location_label = Label(Rinfo, text=Location, font=("bold", 12), width=5 ,anchor=W, bg="Pink") Location_label.grid(column=2, sticky=W,row=rowo) Tcondition_label = Label(Rinfo, text=Tcondition, font=("bold", 12), width=10 ,anchor=W, bg="Magenta") Tcondition_label.grid(column=3, sticky=W,row=rowo) Wcondition_label = Label(Rinfo, text=Wcondition, font=("bold", 12), width=10 ,anchor=W, bg="Lightblue") Wcondition_label.grid(column=4, sticky=W,row=rowo) ##### increment row number rowo += 1 # Date Selection Frame #### end of paste HTH |
I have almost finished this app, pretty happy with it, just have a small issue i can't resolve.
normally when returning data you will have key pairs to work with but the results are not exactly the same. Code:
how can i return the number? |
Here is an almost finished project exe, it is missing a few things like race start time and results and maybe some instructions.
Just run it, select "Today" or "Tomorrow" highlight the "M-Code" for the meeting you want then put in a race number and press "Get Race" It gives you some info in regards to ratings used on tab site, i also noted they show the same fixed prices for all the sites. This is the first program i have written in like 30 years and the first in python, it may be a simple program to some but i am pretty pleased with my efforts as it gave me a better understanding of python i guess, the source code is not pretty and am sure it could be tidied up as there are a few errors. the program is in my One Drive folder in my signature called "Tab_Prices" there is also a text doc with the python code in there. |
I added a 30 second refresh, you can still switch races.
|
This program now collects the results if known and updates every 15 seconds, i would like to colour code the results 1st to 4th, i have tried a few ways but unsuccessful, i have updated the code script if anyone has ideas.
I noticed a bug, will update file when fixed |
Quote:
EDIT, I do apologise, this only seems to work for VIC. Hi Shaun, great job. Unfortunately the move to this new API killed my excel/VBA work as well. I'm new to python, slowly learning the ropes. It is as clunky as hell, and is manually coded, but using your script I have added the start time. Programmers will wince at how bad this is (sorry!). There's easier ways to do timezone conversions so I have read but cannot wrap my head around it yet. **** inserted into # race info **** race_StartTime = race1["raceStartTime"] **** d1 = datetime.datetime.strptime(race_StartTime,"%Y-%m-%dT%H:%M:%S.%fZ") new_format = "%H:%M" HourOnly = "%H" MinuteOnly = "%M" Hour = str(int(d1.strftime(HourOnly))+11) # This is for Victoria AEDT (+11 hrs GMT) Minute = d1.strftime(MinuteOnly) race_StartTime = "Jump:" + Hour + ":" + Minute raceStartTime = Label(inputFrame, text=str(race_StartTime), width=25, bg="darkblue", fg="white", font=("bold", 11), anchor=W) raceStartTime.grid(row=0, column=20) **** |
Quote:
Cheers, this is the same reason i didn't add the time as yet because of time zones, but anyone could adjust this code to suit there own time zone, that issue i was having with the bug had to do with refreshing, the problem i had was when you change races it started another time refresh sequence, probably a simple fix when i work it out. |
cookbook
O'Reilley python cookbook 3 Beazley & Jones
advise using UTC for your time calcs and then moving to local timezone. chapter 3.16, P 110 in third ed. from datetime import datetime #get your UTC date time dt = datetime(2020,12,20,9,31,22) from pytz import timezone nsw = timezone( 'Australia/NSW' ) # = nsw.localize( your UTC date time ) ndt = nsw.localize( dt ) an alternative is to use Queensland time and check to see if you are in summer, by looking at your localtime. i have done that before or, move to Queensland |
Tab_Prices - On your One Drive (Shaun)...
Hi Shaun,
Good to see you are progressing very well with the new python programming language. You have made the python file available on your One Drive..That's great.! My problem is that I cannot locate your One drive option here.(I had this problem a while ago, and you sent me a direct link to your drive, which allowed me to access the drive). Can you please supply me with the link to your drive, so I can access the "TAB_Prices" file. I am looking forward to using it and maybe assisting with enhancing it, although I am in the infancy of using the python language. Please advise....Kind regards. gsdanger |
Tab_Prices - On your One Drive (Shaun)...
Hi Shaun,
Further to my last post...I managed to find a path to your One Drive...Hooray! I assume the code needs to be downloaded and installed into the python area. (excuse my dumbness...). Please advise.......Again please excuse my Dumbness.... Kind Regards....gsdanger |
As long as you have python 3 installed you can copy this code to your IDE or text editor and it should run the same as any code you use, you will need to be sure you have all the modules listed in import, i use Annaconda this has everything installed already.
|
TAB_Prices
Hi Shaun,
Thanks for your prompt response. Thanks for this info. I have python and Anaconda installed, so I will cut and paste the code into my text editor and go from there. You have done a great job in addressing the Unitab de-commissioning. Shaun, is this new code for form analysis, or live price usage? Kind Regards... Please advise....gsdanger |
Just for live pricing and results for now, i did see a link for form but haven't had the time to investigate what it offers, as i have said in an earlier post i was trying to create an all in one app but you could still download this data to excel, there is lots of info on how to get data in to and out of excel on youtube.
|
I just fixed some issues with this program, if you click my one drive link there is a folder "Tab Prices" contains 2 items, one is TabPrices.exe that is the app, download it, open it up, click on "Today" or "Tomorrow" select your meeting by clicking the "M-Code" type the race number in the box and press "Get Race" the race info will be displayed, if the race has been run you will see the top 4 places listed.
To select another race just put in another number and press the button or you can select a new meeting with the M-Code. This version doesn't auto refresh, i am still working on that one, just press "Get Race" to refresh current race. |
Where is you One Drive Path?....again...
Hi Shaun,
You have made your python file available on your One Drive..That's great.! My problem is that I cannot locate your One drive option here.(I had this problem a while ago, and you sent me a direct link to your drive, which allowed me to access the drive). I still cannot work out why I cannot see your One Drive option.....beats me!!! Can you please supply me with the link to your drive, so I can access the "TAB_Prices" file. Please advise....Kind regards. gsdanger |
Quote:
|
Where is you One Drive Path?....again...
To Walkerman....Thank you for your expert advice, education and direction.
I now have visibility of the One Drive options. Have a great day, and Christmas greetings to you, Shaun and all other forum users. Regards...gsdanger |
Quote:
Glad you got it sorted, thanks Walkerman The only thing left on this program to do is get the auto refresh sorted, although my code is sloppy i have learned a great deal. Looking forward to my next project. |
There are a couple bug fixes that i made while testing, i won't post everythime i make a change but i have added a version number that represents the date i make changes, so if any one is interested in keeping up with this or any other project i may do just compare what version you have with the current one, i did update the code posted also here.
|
I have made a couple updates, the current program uses the T/Points as a rating and converts them to a price R/Price so you can look for overs or unders in the top couple runners.
I also found an api link to the form so i can start adding form information. |
TAB api
Have TAB changed their conditions for accessing their api? On their webpage they have an application form in order to connect to TAB. I applied a few years ago but got refused with no explanation.
Looking again, under How it works the api seems to be available. So what is happening? Any clarification would be great. I am still using the Tatts api but TAB have turned off the account features and so I cannot place bets automatically. Ta, Martin |
I haven't looked at placing bets but i know i have access to all prices and form, this is just my experiment in learning to program a functional replacement for excel as i still use gruss to place my bets.
For the moment i am providing all my python code so others can learn. |
Re TAB
Thanks for that. I will look at moving across to TAB's api as soon as I can. Ta, Martin
|
The TAB api is accessible to pull down race data and odds and so on, but to place bets - and any access to the accounting api - you need to be approved by TAB - you will be given a client token that is used to create access tokens each time you place a bet.
When it started you needed to be Silver or (Gold?) status to get betting access to the api - that meant turnover of about $25k per year. Not sure what the situation is now :confused: |
Thanks for that. I don't want to have to throw 25k down the loo on bets I am not sure of. And I do not want to sit at my computer all day, every day to use my software and place bets manually. They have made it too hard if that is still the case. Ta, Martin
|
I am slowly getting python to replace what i used to do in excel, so far i can pull race data and results info, i can also get past form but only what is available on race day but still useful, i have also implemented one of my black book systems to make selections and print out those selections to txt doc.
i am having one issue when getting results if they are not available it throws a KeyError I have looked at a few options for this error but none work, all i need is if no results just to skip this section, the program still runs regardless but better to not have errors i guess. Code:
|
Shaun: try colour like this?
a_res = **** "1st":'darkgreen', "2nd":'gold', "3rd":'blue', "4th":'purple' **** colour = 'black' if res in a_res: colour = a_res[res] key error happens if your key is not in the dictionary. |
Time for an update.
I have spent many hours practicing my python skills, my work is pretty average but functional. my latest creation that can be found in my link is "BSP - 16-05-21" there is an exe plus a txt with code. As with my other programs this will allow you to access the TAB website and gather race info, it collects race results if known. I have included 5 systems, these aren't the holy grail but more ideas on what is possibly with python and some imagination. The program prints out the system bets in a format that can be imported to excel, i also included a timezone list so races are listed in your timezone. There is an info tab that explains how to run things. have fun and any thoughts appreciated. |
All times are GMT +10. The time now is 10:45 PM. |
Powered by: vBulletin Version 3.0.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.