my problem is that I want the second dropdown menu "Operatsioon1" to get it's values based on what is selected in "Pink1". The database PROD_MachineOperations includes both Machine names and the Operatsions. But PROD_Machine also includes the same Machines.
The concept is that I have the names of the machines in a SQL database PROD_Machines, that is the first selection, then based on the machine that is selected it will list the operations that are for that machine in the PROD_MachineOperations database as MACHINE_NAME, OPERATION
from tkinter import *
from tkinter import ttk
import tkinter as tk
import pyodbc
DEFAULT_ENCODING = 'utf-8'
ws=Tk()
ws.title('Test')
ws.geometry('150x100')
ws['bg'] = '#26658f'
ws.resizable(False, False)
con1 = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=192.168.1.8;DATABASE=HUT;UID=######;PWD=######')
cur2 = "SELECT [Machine] FROM PROD_Machines"
cur1 = con1.cursor()
cur1.execute(cur2)
proov1 = [x[0] for x in cur1.fetchall()]
def callback_pink(event):
"""Callback event called by combobox 'Pink1' via Pink1.bind("<<ComboboxSelected>>", callback_pink)"""
con1 = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=192.168.1.8;DATABASE=HUT;UID=######;PWD=#######')
cur3 = "SELECT [Operation] FROM PROD_MachineOperations WHERE [Machine] LIKE (?)"
val2 = (event.widget.get())
cur4 = con1.cursor()
cur4.execute(cur3,val2)
proov2 = [x[0] for x in cur4.fetchall()]
Operatsioon1["values"] = proov2
Operatsioon1.current(len(Operatsioon1["values"])-1)
Operatsioon1.current(0)
cur3 = "SELECT [Operator] FROM PROD_MachineOperators WHERE [Machine] LIKE (?)"
val2 = (event.widget.get())
cur4 = con1.cursor()
cur4.execute(cur3,val2)
proov2 = [x[0] for x in cur4.fetchall()]
Operaator1["values"] = proov2
Operaator1.current(len(Operaator1["values"])-1)
Operaator1.current(0)
Pink_entry = tk.StringVar()
Pink1 = ttk.Combobox(ws, textvariable=Pink_entry, width = 17)
Pink1['values'] = proov1
Pink1['state'] = 'readonly'
Pink1.grid(row=4,column=2,padx=(10, 10))
Pink1.bind("<<ComboboxSelected>>", callback_pink, callback_pink)
Operatsioon_entry = tk.StringVar()
Operatsioon1 = ttk.Combobox(ws, textvariable=Operatsioon_entry, width = 17)
Operatsioon1['state'] = 'readonly'
Operatsioon1.grid(row=6,column=5,padx=(10, 10))
Operaator_entry = tk.StringVar()
Operaator1 = ttk.Combobox(ws, textvariable=Operaator_entry, width = 17)
Operaator1['state'] = 'readonly'
Operaator1.grid(row=4,column=3,padx=(10, 10))
ws.mainloop()