I have wasted hours this morning trying to test all the suggestions found on the web. There must be a simple reason for this I am overlooking.
I have a simple tkinter test app with a New Window button. The new window has a couple of combo boxes (with the current values pulled from a text file) and buttons.
The app works perfectly from Thonny, but when I auto-run it at startup (using a display.desktop autostart file) and the new window is opened, the combo boxes and buttons are not visible.
I have tried making an executable file, same problem. I have tried adding a 'sleep 5', 'sleep 10' in the Autostart no change.
What is the best method to accomplish this?
My code is below. The controls displayed as expected before I changed the combo box 'fill on startup' from one combo box into two default values into two combo boxes.
I have a simple tkinter test app with a New Window button. The new window has a couple of combo boxes (with the current values pulled from a text file) and buttons.
The app works perfectly from Thonny, but when I auto-run it at startup (using a display.desktop autostart file) and the new window is opened, the combo boxes and buttons are not visible.
I have tried making an executable file, same problem. I have tried adding a 'sleep 5', 'sleep 10' in the Autostart no change.
What is the best method to accomplish this?
My code is below. The controls displayed as expected before I changed the combo box 'fill on startup' from one combo box into two default values into two combo boxes.
Code:
#!/usr/bin/env python3# Import moduleimport osfrom tkinter import *from tkinter import messagebox, ttkimport tkinter as tksd_card_path = "/home/user/Python/"file_name = "data.txt"file_path = os.path.join(sd_card_path, file_name)# ----------- New window -------------------------def create_window(): def write_line(line_number, text): with open(file_path, "r") as f: lines = f.readlines() if 0 < line_number <= len(lines): lines[line_number - 1] = text + "\n" else: return "Line number out of range" with open("your_file.txt", "w") as f: f.writelines(lines) messagebox.showinfo( title="Data Update", message="Saved value", parent=new_window ) def read_line(line_number): with open("your_file.txt", "r") as f: lines = f.readlines() if 0 < line_number <= len(lines): return lines[line_number - 1].strip() # Line numbers start at 1 else: return "Line number out of range" def get_value(): delay = (selected_value.get()) write_line(4, "var4 = " + delay) new_window = Toplevel() new_window.title("Settings") new_window.geometry( "400x400" ) label = Label(new_window, text="Settings") label.pack(padx=20, pady=20) button1 = Button( new_window , text = "Exit settings", width=35 ).pack() button2 = Button( new_window , text = "Spare", width=35).pack() button3 = Button( new_window , text = "Exit App", width=35).pack() label1 = Label( new_window , text = "Set Delay " ) label1.place(x=25, y=170) selected_value = tk.StringVar() combo = ttk.Combobox(new_window, textvariable=selected_value) combo['values']=("300","250","225","200","175","150","140","130","125") combo.set(read_line(4)) combo.bind("<<ComboboxSelected>>") #("<<ComboboxSelected>>", selection_changed) combo.place(x=110, y=170) button4 = Button( new_window , text = "Save", command=get_value ) button4.place(x=100, y=260) button5 = Button( new_window , text = "Exit", command=new_window.destroy ) button5.place(x=160, y=260) # --------------- Main window -------------------------------root = Tk() root.title(" Main Window ")root.geometry( "400x500" ) #(HxV)button = Button( root , text = "Settings" , command = create_window )button.place(x=150, y=200)# Execute tkinter root.mainloop() Statistics: Posted by Ashton — Sat Dec 06, 2025 8:23 pm