Fair warning - I'm still learning so this might be a very newb like question:

What I'm trying to do:
I'm trying to import a python file into a Tkinter window and run it when I press a button. Eventually I'd like to display the output of the imported script (yahooKeyStats) into a separate window and then save it to a text file but I am still learning how to do that

The current issue:
When I import "yahooKeyStats" then convert it to tsx for use within this script the yahooKeyStats module seems to run before the tkinter window is generated - the Tkinter window never seems to come up nor the exit button. I can post the other script if it helps but it's become rather large and cumbersome. Where am I going wrong?

Thank you for your time:)

I added codeusing the </> Code button but not seeing it here for some reason -- trying to delete this

`from tkinter import *
from TSX import yahooKeyStats as tsx # import TSX.py and name it tsx for reference here

Here, we are creating our class, Window, and inheriting from the Frame
class. Frame is a class from the tkinter module. (see Lib/tkinter/init)

class Window(Frame):

# Define settings upon initialization. Here you can specify
def __init__(self, master=None):

    # parameters that you want to send through the Frame class. 
    Frame.__init__(self, master)   

    #reference to the master widget, which is the tk window                 
    self.master = master

    #with that, we want to then run init_window, which doesn't yet exist
    self.init_window()

#Creation of init_window
def init_window(self):

    # changing the title of our master widget      
    self.master.title("GUI")

    # allowing the widget to take the full space of the root window
    self.pack(fill=BOTH, expand=1)

    # creating a button instance
    quitButton = Button(self, text="Exit",command=self.client_exit)

    # placing the button on my window
    quitButton.place(x=0, y=0)

     # creating a button instance
    TSXButton = Button(self, text="Scan TSX Yahoo for Value Stocks",command=self.client_GrahamScan)

    # placing the button on my window
    TSXButton.place(x=100, y=0)     

def client_exit(self):
    exit()

def client_GrahamScan(self):
    tsx()
root window created. Here, that would be the only window, but
you can later have windows within windows.

root = Tk()

root.geometry("800x600")

creation of an instance

app = Window(root)

mainloop

root.mainloop() `

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.