0

Instead of having a user input "Job Name", I want it to be a Tkinter drop down menu.

Im guessing the idea will be to append Jobname with the list of names from Table. How will it have it show in the tkinter dropdown?

Jobname = []
...
for row in rows:
        data = "%s %s %s %s %s" % (row["Id"], row["Title"], row["Date"], row["Time"], row["Duration"])
        movieList.append(data)
        print data

My Code

def reportdata():
    clear()
    w11 = Label(fr, text="Job Name : ")
    w11.grid(row=1, column=0)
    listlab.append(w11)
    w22 = Label(fr, text="Job Start Date: ")
    w22.grid(row=2, column=0)
    listlab.append(w22)
    w33 = Label(fr, text="Job End Date: ")
    w33.grid(row=3, column=0)
    listlab.append(w33)

    e11 = Entry(fr, textvariable=jjname)
    e11.grid(row=1, column=1)
    listlab.append(e11)
    e22 = Entry(fr, textvariable=jjdates)
    e22.grid(row=2, column=1)
    listlab.append(e22)
    e33 = Entry(fr, textvariable=jjdatee)
    e33.grid(row=3, column=1)
    listlab.append(e33)

    mbuttonn = Button(fr, text="Generate", command=savexl)
    mbuttonn.grid(row=4, column=3)
    listlab.append(mbuttonn)
2
  • Have you tried anything? You are not showing any attempt to use OptionMenu or any data fetching from sql table. Commented Aug 17, 2017 at 14:43
  • I have updated it. Please take a look Commented Aug 17, 2017 at 15:01

1 Answer 1

2

Please see below for an example of how you can use a list to populate a tkinter OptionMenu:

from tkinter import *

root = Tk()

a = [] #creates a list to store the job names in
var = StringVar() #creates a stringvar to store the value of options

for i  in range(20): #fills list with nonsense jobs for troubleshooting
    a.append("Job Name "+str(i))

var.set(a[0]) #sets the default option of options

options = OptionMenu(root, var, *a) #createa an optionmenu populated with every element of the list
button = Button(root, text="Ok", command=lambda:print(var.get())) #prints the current value of options

options.pack()
button.pack()

This uses a list to fill out an OptionMenu with all of it's elements, then we create a button which prints the current value of the OptionMenu.

If you can get your SQL imported data into a list you can use the same logic as above.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.