Don't be afraid of the length of the question. The help I need is very simple, but it is right to enter a detailed and precise question. What I have to do is simple, that is to combine the "tournament" combobox with the "rounds" combobox, because I would like to save match data within each round of each different tournament. I think I have done almost everything well, I approach the solution, yet I cannot because I'm new to Python. The code is all written, but it needs a little fixing in the "combobox rounds" part.
PROBLEM: I don't get errors, but the problem is that rounds (1, 2, 3, 4, etc) do not open in the combobox Round when I select a tournament in the "tournament" combobox. Each Round must be combined with the relevant Tournament, so that I enter the data and they are saved in each different round number ... of each different tournament. Then I change Tournament in the "Tournament" combobox and change the rounds. I'm wrong in "combobox rounds" (in the code I wrote THE PROBLEM IS HERE). The code consists of "Combox Tournament", "Combobox Teams" (these 2 work well and are combined well with each other) and "Combobox Rounds" which does not work. Who is capable and patient enough to help me? Thanks
PREMISE:
- Within each TOURNAMENT, there are 38 rounds. So each particular tournament will each have 38 different rounds: Serie A: 38 rounds, Serie B: 38 rounds, Series C: 38 rounds
- Inside each ROUND there are 10 matches (team vs team x10)
I WANT TO DO THIS:
- I open the "Tournament" combobox and select a tournament
- Subsequently the combobox ROUND will be activated in which the 38 rounds will be present.
- Then I select the ROUND combobox (round1, round2, round3, etc.), starting from Round 1, and insert the matches into it (each round will have different matches). The "Round" combobox must be connected to "Tournaments", so that you can save a match on each different day of each different tournament
THE DATABASE I OWN In the database I have created a TEAM table, so that I can create a match (team A vs team B). Then I created the table with the name of the TOURNAMENTS in which the name of the teams is combined with the relative tournaments. Then again I created a table of the ROUNDS in which I insert the rounds from 1 to 38 each with the id of the relative to the tournament. So from 1 to 38 for the Serie A tournament, from 1 to 38 for the Serie B tournament, etc
This is the Rounds table:
CREATE TABLE "All_Rounds" (
"ID_round" INTEGER,
"tournament" INTEGER,
"rounds" INTEGER,
PRIMARY KEY("ID_Round" AUTOINCREMENT),
FOREIGN KEY("tournament") REFERENCES "All_tournament"("ID_tournament")
);
Contains this:
ID_Round | Tournament | Rounds
1 435 1
2 435 2
3 435 3
4 435 ...
... 435 38
... 436 1
... 436 2
... 436 ...
... 436 38
The code is very long, so I only paste the useful parts. The code consists of "Combox Tournament", "Combobox Teams" (these 2 work well and are combined well with each other) and "Combobox Rounds" which does not work:
#COMBOBOX TOURNAMENT
lbl_tournament = Label(root, text="tournament", font=("Calibri", 11), bg="#a8dd71", fg="white")
lbl_tournament.place(x=6, y=60)
combo_tournament = ttk.Combobox(root, font=("Calibri", 11), width=30, state="readonly")
combo_tournament.place(x=180, y=60)
combo_tournamentset("Select tournament")
def combo_tournament():
cursor.execute('SELECT tournament_name FROM All_tournament')
result=[row[0] for row in cursor]
return result
combo_tournament['value'] = combo_tournament()
combo_tournament.set("Select")
###################################
#COMBOBOX TEAMS
#it is used to enter the teams related to each tournament, then to create the combinations
#of matches to be included in the rounds. this works fine, ok
lbl_teams = Label(root, text="teams", font=("Calibri", 11), bg="white", fg="black")
lbl_teams.place(x=6, y=110)
combo_teams = ttk.Combobox(root, font=("Calibri", 11), width=30, state="readonly")
combo_teams.place(x=180, y=110)
combo_teams.set("Select teams")
def combo_teamssss(event=None):
val = combo_tournament.get()
cursor.execute('SELECT s.teams FROM All_teams s, All_tournament c WHERE s.ID_tournament=c.ID_tournament AND c.teams = ?', (val,))
result=[row[0] for row in cursor]
combo_teams['value'] = result
combo_teams.current(0)
return result
combo_teams['value'] = combo_tournament()
combo_teams.set("Select")
combo_tournament.bind('<<ComboboxSelected>>', combo_teamssss)
###################################
#THE PROBLEM IS HERE
#COMBOBOX ROUND
lbl_rounds = Label(root, text="rounds", font=("Calibri", 11), bg="#a8dd71", fg="white")
lbl_rounds.place(x=600, y=60)
combo_rounds = ttk.Combobox(root, font=("Calibri", 11), width=30, textvariable=rounds, state="readonly")
combo_rounds.place(x=680, y=60)
combo_rounds.set("Select rounds")
def combo_roundsss(event=None):
val = combo_tournament.get()
cursor.execute('SELECT rounds From All_rounds WHERE tournament = 435', (val,)
cursor.execute('SELECT rounds From All_rounds WHERE tournament = 436', (val,)
cursor.execute('SELECT rounds From All_rounds WHERE tournament = 437', (val,))
result=[row[0] for row in cursor]
combo_rounds['value'] = result
combo_rounds.current(0)
return result
combo_rounds['value'] = combo_tournament()
combo_tournament.bind('<<ComboboxSelected>>', combo_roundsss)