Python Forum
Help Using combobox in a select statement variable - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Help Using combobox in a select statement variable (/thread-27501.html)



Help Using combobox in a select statement variable - cibb - Jun-09-2020

I'm creating a small App that will list values from a mysql database to a combobox. The user will select one of those values then click a button. This button will need to get the value selected from the combobox. It will then perform another select statement using the value in the combobox as a variable in the select statement and then execute a windows shell command.

I've got a sql select statement listing values in a tkinter combobox.

I'm having trouble with the combobox. Do I bind or get the value?


RE: Help Using combobox in a select statement variable - Knight18 - Jun-09-2020

Are you having trouble returning the combobox value?


RE: Help Using combobox in a select statement variable - cibb - Jun-09-2020

Essentially yes.

I'm not sure if I can assign the get to a variable and then have a button event to execute the command.

example: variable = "SELECT DB.ID from DB WHERE DB.NAME = "comboboxvalue"

install_command = subprocess.Popen("cmd.exe /c setup.exe variable")

button event button1 = Button(root, text="Install", command=install_command)

I hope that helps to see where I'm wanting to go with it. I still have a lot to work out syntax and logic wise I just wanted to get some help getting started.

from tkinter import *
from tkinter.ttk import *
import mysql.connector


root = Tk()
root.title('Software Installation')
root.geometry("400x400")

conn = mysql.connector.connect(host="x.x.x.x",
                               user="UN",
                               passwd="1234",
                               database="myDb")

c = conn.cursor()

query = "Select DB.NAME from DB Where DB.ENABLED = True"


c.execute(query)
rows=c.fetchall()
# Create Combobox
combo = Combobox(root,values=rows)
combo.pack()



button1 = Button(root, text="Install")
button1.pack()

root.mainloop()