1

I've been trying some GUI programming and needed help with the below code. I am trying to run a button functioning which needs to return a list and i need to use that in a Combobox. But the list is not getting used in Combobox.

import tkinter as tk
from functools import partial
from tkinter import ttk
f=[]
def getlist(a):
    li=[]
    f=[]
    if a==2:
        li=[1,2,3,4,5,6]
        for i in li:
            f.append(li.get())      
    else:
        return False

root=tk.Tk()
root.title('Hello')
root.geometry('250x250')

ttk.Label(root, text = "Press the button",font = ("Times New Roman", 10)).grid(column = 0,row = 1, padx = 10, pady = 25)

tk.Button(root,text='Press',command=getlist(8)).grid(row=2,column=0)

a = tk.StringVar()
namechoosen = ttk.Combobox(root, width = 27, textvariable = a)
namechoosen['values'] = f
namechoosen.grid(column=0,row=3)
namechoosen.current()
window.mainloop()
martineau
  • 119,623
  • 25
  • 170
  • 301
  • There are other things wrong with your code besides the issue related to the duplicate question, however I'm not sure how to tell you to fix them because I don't understand what you're trying to accomplish. If you post a related follow-on question, please try to make that as clear as possible. – martineau Jun 17 '21 at 10:42

1 Answers1

-1

I'm gussing tk.Button(root,text='Press',command=getlist(8)).grid(row=2,column=0) went wrong

I make some change it actually call the func.

import tkinter as tk
from tkinter import ttk

f = []


def getlist(a):
    print("func call")
    li = []
    f = []
    if a == 2:
        li = [1, 2, 3, 4, 5, 6]
        for i in li:
            f.append(li.get())
    else:
        return False


root = tk.Tk()
root.title('Hello')
root.geometry('250x250')

ttk.Label(root, text="Press the button", font=("Times New Roman", 10)).grid(column=0, row=1, padx=10, pady=25)

tk.Button(root, text='Press', command=lambda: getlist(8)).grid(row=2, column=0)

a = tk.StringVar()
namechoosen = ttk.Combobox(root, width=27, textvariable=a)
namechoosen['values'] = f
namechoosen.grid(column=0, row=3)
namechoosen.current()
root.mainloop()
pepper
  • 353
  • 1
  • 7