Python Forum
tkinter GUI, problem running seperate files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tkinter GUI, problem running seperate files
#1
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:

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()
Reply


Messages In This Thread
tkinter GUI, problem running seperate files - by fishglue - Sep-24-2019, 01:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Help running a loop inside a tkinter frame Konstantin23 3 1,662 Aug-10-2023, 11:41 AM
Last Post: Konstantin23
  Why is the program not running? Is there a logical or syntax problem? behi00 10 2,251 Apr-01-2023, 12:50 AM
Last Post: woooee
  [Tkinter] Have tkinter button toggle on and off a continuously running function AnotherSam 5 5,110 Oct-01-2021, 05:00 PM
Last Post: Yoriz
  Python3 tkinter radiobutton problem Nick_tkinter 14 6,250 Feb-15-2021, 11:01 PM
Last Post: Nick_tkinter
  tkinter python button position problem Nick_tkinter 3 3,635 Jan-31-2021, 05:15 AM
Last Post: deanhystad
  [Tkinter] ClockIn/Out tkinter problem Maryan 2 2,271 Oct-12-2020, 03:42 AM
Last Post: joe_momma
  tkinter| listbox.insert problem Maryan 3 3,592 Sep-29-2020, 05:34 PM
Last Post: Yoriz
  Tkinter problem DPaul 6 4,244 May-28-2020, 03:40 PM
Last Post: DPaul
  [Tkinter] Tkinter - I have problem after import varaible or function from aGUI to script johnjh 2 2,641 Apr-17-2020, 08:12 PM
Last Post: johnjh
  [Tkinter] Problem with tkinter when creating .exe file Jan_97 2 4,659 Feb-27-2020, 05:17 PM
Last Post: Jan_97

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020