Sep-24-2019, 01:43 PM
Hello. I'm fairly new to Python.
If I run the program from my editor it works fine, every .py file opens when buttons is pressed and does what it's supposed to. Once I try to double click the main program or run it with a hotkey, and click the button that opens the .py file, nothing happens. In this case the button labeled "test" inside class StartPage.
What I want to happen: The program has to open seperate .py files when a button is clicked, when the program is started with a hotkey.
I have tried:
-subprocess.Popen
-subprocess.call
-os
-change to .pyw
-pythonpath
-specified pathing to .py file
I run python 3.7
Windows 10 MSC v.1915 64 bit (AMD64)
The code is 400 lines, so I made it a bit shorter:
If I run the program from my editor it works fine, every .py file opens when buttons is pressed and does what it's supposed to. Once I try to double click the main program or run it with a hotkey, and click the button that opens the .py file, nothing happens. In this case the button labeled "test" inside class StartPage.
What I want to happen: The program has to open seperate .py files when a button is clicked, when the program is started with a hotkey.
I have tried:
-subprocess.Popen
-subprocess.call
-os
-change to .pyw
-pythonpath
-specified pathing to .py file
I run python 3.7
Windows 10 MSC v.1915 64 bit (AMD64)
The code is 400 lines, so I made it a bit shorter:
import tkinter as tk from tkinter import ttk import subprocess import time class MainClass(tk.Tk): def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) container = tk.Frame(self) self.geometry("1000x700+300+60") container.pack(side="top", fill="both", expand = True) container.grid_rowconfigure(0, weight=1) container.grid_columnconfigure(0, weight=1) self.frames = {} for F in (StartPage, PageOne, PageTwo, PageThree, PageFour, PageFourSubOne, PageFive, PageSix): frame = F(container, self) self.frames[F] = frame frame.grid(row=0, column=0, sticky="nsew") self.show_frame(StartPage) def show_frame(self, cont): frame = self.frames[cont] frame.tkraise() class StartPage(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self,parent) label = tk.Label(self, text="Hovedmeny", font=("arial", 20), fg="Blue") label.pack(pady=10,padx=10) def test(): subprocess.call("autoguitest2.py", shell=True) controller.show_frame(StartPage) #input('1: press enter to continue') (Coudn't get this working) testbase = ttk.Button(self, text="Test", command=test) testbase.pack() class PageOne(tk.Frame): def __init__(self, parent, controller): tk.Frame.__init__(self, parent) label = tk.Label(self, text="CO2", font=LARGE_FONT) label.pack(pady=10,padx=10) style = ttk.Style() style.configure("tilbake.TButton", width=20, height=2, font=('arial', 12, "bold"), bg="Blue") hovedmeny = ttk.Button(self, text="Tilbake til hovedmenyen", style="tilbake.TButton", command=lambda: controller.show_frame(StartPage)) hovedmeny.pack() label = tk.Label(self, text="Label", font=('arial', 15, "bold"), fg="Red") label.pack(pady=10,padx=10) def trekilo_ordre(): subprocess.call("CO2.py", shell=True) controller.show_frame(StartPage) style.configure("3kg.TButton", width=40, height=2, font=("arial", 12, "bold")) trekilo = ttk.Button(self, text="CO2 3kg", style="3kg.TButton", command=trekilo_ordre) app = MainClass() app.mainloop()