Smartgambler
Pro-Punter

Go Back   OZmium Sports Betting and Horse Racing Forums > Public Forums > General Topics
User Name
Password
Register FAQ Search Today's Posts Mark all topics as read

To advertise on these
forums, e-mail us.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 8th October 2020, 10:43 AM
Shaun Shaun is offline
Member
 
Join Date: Jan 1970
Location: Western Australia
Posts: 3,457
Default 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:
from tkinter import * from tkcalendar import Calendar,DateEntry import json import requests app = Tk() app.title("Todays Races") app.geometry("1000x500") app.resizable(width=False, height=False) date_label = Label(app, text="Input Date", font=("bold", 14), pady=20) date_label.pack() cal = DateEntry(app,width=30,bg="darkblue",fg="white",date_pattern='yyyy-mm-dd',year=2020) cal.pack() date_btn = Button(app, text="Go", width=8, command=lambda: get_json()) date_btn.pack() def get_json(): state = "VIC" date = cal.get() url = "https://api.beta.tab.com.au/v1/tab-info-service/racing/dates/" + str(date) + "/meetings?jurisdiction=" + state data = requests.get(url) data1 = json.loads(data.content) Venues = data1["meetings"] for Venue in Venues: Rtype = Venue["raceType"] track = Venue["meetingName"] Rstate = Venue["location"] Wcondition = Venue["weatherCondition"] Tcondition = Venue["trackCondition"] states = ("VIC","NSW","QLD","SA","WA","TAS","ACT") if Rtype == "R" and Rstate in states: text = track + " " + Rstate + " " + Tcondition + " " + Wcondition print(text) app.mainloop()
__________________
One Drive

"If the corporates are treating you poorly , just go elsewhere."
"If they need you , they will soon find out."
"If you need them , you will soon find out."
--moeee
_______________________________________________
Reply With Quote
  #2  
Old 8th October 2020, 11:51 AM
Shaun Shaun is offline
Member
 
Join Date: Jan 1970
Location: Western Australia
Posts: 3,457
Default

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:
from tkinter import * from tkcalendar import Calendar,DateEntry import json import requests app = Tk() app.title("Todays Races") app.geometry("1000x500") app.resizable(width=False, height=False) date_label = Label(app, text="Input Date", font=("bold", 14), pady=20) date_label.pack() cal = DateEntry(app,width=30,bg="darkblue",fg="white",date_pattern='yyyy-mm-dd',year=2020) cal.pack() date_btn = Button(app, text="Go", width=8, command=lambda: get_json()) date_btn.pack() def get_json(): try: state = "VIC" date = cal.get() url = "https://api.beta.tab.com.au/v1/tab-info-service/racing/dates/" + str(date) + "/meetings?jurisdiction=" + state data = requests.get(url) data1 = json.loads(data.content) Venues = data1["meetings"] for Venue in Venues: Rtype = Venue["raceType"] track = Venue["meetingName"] Rstate = Venue["location"] Wcondition = Venue["weatherCondition"] Tcondition = Venue["trackCondition"] states = ("VIC","NSW","QLD","SA","WA","TAS","ACT") if Rtype == "R" and Rstate in states: text = track + " " + Rstate + " " + Tcondition + " " + Wcondition text_label = Label(app, text=str(text)) text_label.pack() except: pass app.mainloop()
__________________
One Drive

"If the corporates are treating you poorly , just go elsewhere."
"If they need you , they will soon find out."
"If you need them , you will soon find out."
--moeee
_______________________________________________
Reply With Quote
  #3  
Old 14th October 2020, 12:48 AM
Shaun Shaun is offline
Member
 
Join Date: Jan 1970
Location: Western Australia
Posts: 3,457
Default

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:
from tkinter import * from tkcalendar import Calendar,DateEntry import json import requests app = Tk() app.title("Todays Races") app.geometry("1000x500") app.configure(bg='Lightblue') app.resizable(width=False, height=False) #Clears Daily Race Meetings def Fclear(): for widget in Rinfo.winfo_children(): widget.destroy() #Collects Daily Race Meetings def get_json(): state = "VIC" date = cal.get() url = "https://api.beta.tab.com.au/v1/tab-info-service/racing/dates/" + str(date) + "/meetings?jurisdiction=" + state data = requests.get(url) data1 = json.loads(data.content) Venues = data1["meetings"] for Venue in Venues: Rtype = Venue["raceType"] Mname = Venue["meetingName"] Location = Venue["location"] Wcondition = Venue["weatherCondition"] Tcondition = Venue["trackCondition"] 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="Lightblue") Mname_label.grid(column=0, sticky=W) Location_label = Label(Rinfo, text=Location, font=("bold", 12), width=5 ,anchor=W, bg="Lightblue") Location_label.grid(column=2, sticky=W) Tcondition_label = Label(Rinfo, text=Tcondition, font=("bold", 12), width=10 ,anchor=W, bg="Lightblue") Tcondition_label.grid(column=3, sticky=W) Wcondition_label = Label(Rinfo, text=Wcondition, font=("bold", 12), width=10 ,anchor=W, bg="Lightblue") Wcondition_label.grid(column=4, sticky=W) # Date Selection Frame Dateframe = Frame(app, bg="Lightblue") Dateframe.grid(row=0, column=0, sticky=W) #Frame widgets date_label = Label(Dateframe, text="Input Date", font=("bold", 14), bg="Lightblue") date_label.grid(row=0, column=0) cal = DateEntry(Dateframe,width=15, bg="darkblue", fg="white", date_pattern='yyyy-mm-dd',year=2020) cal.grid(row=0, column=2) date_btn = Button(Dateframe, text="Go", width=8, bg="Lightgreen", command=get_json) date_btn.grid(row=0, column=3) delete_btn = Button(Dateframe, text="Clear", width=8, bg="#ff704d", command=Fclear) delete_btn.grid(row=0, column=4) #Headings frame Headingsframe = Frame(app, bg="Lightblue") Headingsframe.grid(row=1, column=0, sticky=W) #Race Info Headings htrack = Label(Headingsframe, text="Track", pady=10, font=("bold", 14),anchor=W, width=15, fg="Blue", bg="Lightblue") htrack.grid(row=0, column=0) hstate = Label(Headingsframe, text="State", pady=10, font=("bold", 14),anchor=W, width=5, fg="Blue", bg="Lightblue") hstate.grid(row=0, column=2) hcondition = Label(Headingsframe, text="Condition", pady=10, font=("bold", 14),anchor=W, width=10, fg="Blue", bg="Lightblue") hcondition.grid(row=0, column=3) hweather = Label(Headingsframe, text="Weather", pady=10, font=("bold", 14),anchor=W, width=10, fg="Blue", bg="Lightblue") hweather.grid(row=0, column=4) #Race Info Frame Rinfo = Frame(app, bg="lightblue") Rinfo.grid(row=2, column=0, sticky=W) app.mainloop()
__________________
One Drive

"If the corporates are treating you poorly , just go elsewhere."
"If they need you , they will soon find out."
"If you need them , you will soon find out."
--moeee
_______________________________________________
Reply With Quote
  #4  
Old 14th October 2020, 03:38 AM
chook chook is offline
Member
 
Join Date: Jan 2019
Posts: 14
Default

try .strip()
on the entries
Reply With Quote
  #5  
Old 14th October 2020, 03:58 AM
chook chook is offline
Member
 
Join Date: Jan 2019
Posts: 14
Default

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
Reply With Quote
  #6  
Old 14th October 2020, 05:30 AM
chook chook is offline
Member
 
Join Date: Jan 2019
Posts: 14
Smile

label.grid( row=0,column=0,sticky=w)
Reply With Quote
  #7  
Old 14th October 2020, 09:08 AM
Shaun Shaun is offline
Member
 
Join Date: Jan 1970
Location: Western Australia
Posts: 3,457
Default

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
__________________
One Drive

"If the corporates are treating you poorly , just go elsewhere."
"If they need you , they will soon find out."
"If you need them , you will soon find out."
--moeee
_______________________________________________
Reply With Quote
  #8  
Old 14th October 2020, 10:19 AM
Shaun Shaun is offline
Member
 
Join Date: Jan 1970
Location: Western Australia
Posts: 3,457
Default

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:
from tkinter import * from tkcalendar import Calendar,DateEntry import json import requests app = Tk() app.title("Todays Races") app.geometry("1000x500") app.configure(bg='Lightblue') app.resizable(width=False, height=False) #Clears Daily Race Meetings def Fclear(): for widget in Rinfo.winfo_children(): widget.destroy() #Collects Daily Race Meetings def get_json(): state = "VIC" date = cal.get() url = "https://api.beta.tab.com.au/v1/tab-info-service/racing/dates/" + str(date) + "/meetings?jurisdiction=" + state data = requests.get(url) data1 = json.loads(data.content) Venues = data1["meetings"] for V in Venues: Rtype = V["raceType"] Mname = V["meetingName"] Location = V["location"] Wcondition = V["weatherCondition"] Tcondition = V["trackCondition"] states = ("VIC","NSW","QLD","SA","WA","TAS","ACT") if Rtype == "R" and Location in states: #Race Info frame Rinfo = Frame(app, width=100, bg="green") Rinfo.grid(columnspan=1) #Race info Mname_label = Label(Rinfo, text=Mname, font=("bold", 12), width=20, anchor=W, bg="red") Mname_label.pack(side=LEFT) Location_label = Label(Rinfo, text=Location, font=("bold", 12), width=5 ,anchor=W, bg="red") Location_label.pack(side=LEFT) Tcondition_label = Label(Rinfo, text=Tcondition, font=("bold", 12), width=10 ,anchor=W, bg="red") Tcondition_label.pack(side=LEFT) Wcondition_label = Label(Rinfo, text=Wcondition, font=("bold", 12), width=10 ,anchor=W, bg="red") Wcondition_label.pack(side=LEFT) # Date Selection Frame Dateframe = Frame(app, bg="Lightblue") Dateframe.grid(row=0, column=0, sticky=W) #Frame widgets date_label = Label(Dateframe, text="Input Date", font=("bold", 14), bg="Lightblue") date_label.grid(row=0, column=0) cal = DateEntry(Dateframe,width=15, bg="darkblue", fg="white", date_pattern='yyyy-mm-dd',year=2020) cal.grid(row=0, column=2) date_btn = Button(Dateframe, text="Go", width=8, bg="Lightgreen", command=get_json) date_btn.grid(row=0, column=3) delete_btn = Button(Dateframe, text="Clear", width=8, bg="#ff704d", command=Fclear) delete_btn.grid(row=0, column=4) #Headings frame Headingsframe = Frame(app, bg="Lightblue") Headingsframe.grid(row=1, column=0, sticky=W) #Race Info Headings htrack = Label(Headingsframe, text="Track", pady=10, font=("bold", 12),anchor=W, width=20, fg="Blue", bg="yellow") htrack.grid(row=0, column=0) hstate = Label(Headingsframe, text="State", pady=10, font=("bold", 12),anchor=W, width=5, fg="Blue", bg="orange") hstate.grid(row=0, column=2) hcondition = Label(Headingsframe, text="Condition", pady=10, font=("bold", 12),anchor=W, width=10, fg="Blue", bg="blue") hcondition.grid(row=0, column=3) hweather = Label(Headingsframe, text="Weather", pady=10, font=("bold", 12),anchor=W, width=10, fg="Blue", bg="green") hweather.grid(row=0, column=4) app.mainloop()
__________________
One Drive

"If the corporates are treating you poorly , just go elsewhere."
"If they need you , they will soon find out."
"If you need them , you will soon find out."
--moeee
_______________________________________________
Reply With Quote
  #9  
Old 14th October 2020, 10:54 AM
chook chook is offline
Member
 
Join Date: Jan 2019
Posts: 14
Default

#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
Reply With Quote
  #10  
Old 14th October 2020, 11:06 AM
Shaun Shaun is offline
Member
 
Join Date: Jan 1970
Location: Western Australia
Posts: 3,457
Default

I will also try this as it may be useful moving forward with this project.
__________________
One Drive

"If the corporates are treating you poorly , just go elsewhere."
"If they need you , they will soon find out."
"If you need them , you will soon find out."
--moeee
_______________________________________________
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Forum Jump



All times are GMT +10. The time now is 11:22 PM.


Powered by: vBulletin Version 3.0.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
©2008 OZmium Pty. Ltd. All rights reserved . ACN 091184655