Home > Enterprise >  tkinter comboxes don't appear after converting the GUI app to a .exe
tkinter comboxes don't appear after converting the GUI app to a .exe

Time:01-28

I have created a GUI application with tkinter for data analysis. In the app I have several comboxes to list down the sheets of an uploaded excel file. The user can select a sheet name from the combox and the code will read the columns to process the data analysis.

Everything works in Python environment without producing an error. I converted the tkinter application by using both pyinstaller and auto-py-to-exe.

My problem is tkinter comboxes aren't functional in the .exe. They worked perfectly in the .py script but in .exe they are not even appearing after uploading. What could be the possible issue for this?

with pyinstaller I used the command:

pyinstaller --onefile --windowed name_of_script.py

and with Auto Py I browsed to my program and converted it.

this is how I created comboxes in .py

proboxATC = ttk.Combobox(self, textvariable=proATC_com, value=pathATC_sheets,state='readonly')

proboxATC.bind("<<ComboboxSelected>>",ATC_selected)

Here is a minimum working example. As you can see it works as a .py but the combox doesn't appear in the .exe.

import tkinter as tk
from tkinter import ttk
from tkmacosx import Button
import pandas as pd

root = tk.Tk()
root.geometry('400x400')

def OOE():        
   pathxl = tk.filedialog.askopenfilename(filetypes = [('Excel files', '*.xls*')], title = "Select an ATC file")  
   excel_file = pd.ExcelFile(pathxl)
   sheet_names = excel_file.sheet_names
   combo = tk.StringVar()
   def selected(event):
       print(box.get())                
 
   box = ttk.Combobox(root, textvariable=combo, value =sheet_names, state='readonly')
   box.bind("<<ComboboxSelected>>",selected)
   box.pack()

xl_btn = Button(root,text="ATC",foreground='#161327',background="#707087",command=lambda:OOE())
xl_btn.pack()

root.mainloop()   

CodePudding user response:

I was able to compile and run your program fine. I did have to add the following line to the imports at the top in order to get the filedialog to work, but I don't think this is necessary on all systems.

import tkinter.filedialog   # added this line

And I also added openpyxl to the --hidden imports flag for pyinstaller.

pyinstaller -F -w --hidden-import openpyxl main.py
  • Related