0

so i want to open a new python tkinter program when i click a button in the GUI. As soon as i run the code ProgramB runs. When i close this GUI the main GUI runs but when i click the button in this GUI, it doesn't open ProgramB. I'm Learning pyhton and tkinter and don't know how to fix this problem. Thank you in advance.

My main code:

from tkinter import *
from tkinter.ttk import *
import basis_tkinter
import subprocess

mainwindow = Tk()
mainwindow.title= "test opening new file"

def open():
    subprocess.call("basis_tkinter.py", shell=True)

btnopen = Button(mainwindow, text="open new program", command=lambda: open).pack()

mainwindow.mainloop()

Program B (basis_tkinter):

from tkinter import *


MainWindow = Tk()
MainWindow.title("Title")
MainWindow.iconbitmap(r'C:\Users\Gebruiker\Documents\school 2020-2021\stage\interface\Afbeeldingen\Apex icon.ico')
Background= Label(MainWindow, image=PhotoImage(file=r"C:\Users\Gebruiker\Documents\school 2020-2021\stage\interface\Afbeeldingen\Apex logo.png"))
Background.place(x=0,y=0, relwidth=1, relheight=1)
MainWindow.geometry("400x400")

def clicked():
    label = Label(MainWindow, text="You clicked").pack()

button = Button(MainWindow, text="Click me", command=clicked).pack()


MainWindow.mainloop()
Seppe
  • 23
  • 4
  • This is a duplicate question. See the answer [here](https://stackoverflow.com/a/65777004/5568675). – Dbercules Feb 25 '21 at 10:52
  • I tried your suggestion but it stil runs on startup. But the button now works like it is supposed to – Seppe Feb 25 '21 at 11:01
  • 3
    You should not `import basis_tkinter` in your main application. And `command=lambda: open` should be `command=open`. – acw1668 Feb 25 '21 at 11:06

0 Answers0