Reputation: 71
I am working on a project where I required defined function variable(local variable) in the values of Combobox but it gives me error of undefined variable. And I cannot change the pattern of my python script otherwise the script will mixed up and gives other error.
Please help me to solve the problem without changing the script pattern.
Here is my code:-
book= ''
pages = 1
page_no = 1
pdfReader=''
def selectBtnClicked():
# pass
global book
global PDFFILE
global pages
global page_no
global pdfReader
print(PDFFILE)
# PDFFILE1=pdf_btnClicked()
book = open(PDFFILE, 'rb')
pdfReader = PyPDF2.PdfFileReader(book)
pages = pdfReader.numPages
print(pages)
pages += 1
page_no = [i for i in range(1, pages)]
print(page_no)
return page_no, pdfReader
#start from
style = ttk.Style()
style.theme_use("default")
style.map('TCombobox', fieldbackground=[('readonly','red')])
style.map('TCombobox', selectbackground=[('readonly', 'red')])
style.map('TCombobox', selectforeground=[('readonly', 'white')])
n= tk.StringVar(value="---STARTING PAGE---")
n.set("---STARTING PAGE---")
startfromLabel = ttk.Combobox(root, font=font, justify='center', textvariable=n)
startfromLabel["values"]= page_no
# pages_nos()
startfromLabel["state"] = "readonly"
startfromLabel.bind('<<ComboboxSelected>>')
startfromLabel.current()
startfromLabel["foreground"] = '#ffffff'
startfromLabel.pack(side=TOP, pady=30)
root.mainloop()
I need page_no as value of startfromLabel but I am not getting the values in my GUI output:
Upvotes: 1
Views: 92
Reputation: 15088
Your not telling to change the values
inside the function, so say:
def selectBtnClicked():
.... #same bunch of code
startfromLabel["values"] = page_no
.... #remaining bunch of code
Upvotes: 1