0

I have a script, and woult like to have some imputs, outputs (as in the terminal) and a start running script.

How can I do this?

this is what I have for now:

class Window(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.master = master

        exitButton = Button(self, text="Run", command=self.clickExitButton)
        exitButton.place(x=0, y=0)

def clickrunButton(self):
        run() #this doesnt work

root = Tk()
app = Window(root)


# set window title
root.wm_title("Tkinter window")

# show window
root.mainloop()
1
  • app.pack() ?? Commented Nov 12, 2022 at 14:00

1 Answer 1

1

You have to place your app in the root, for example with pack(). You also have to change the name of the function, because it doesn't match the one you give to the button command.

from tkinter import *

class Window(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.master = master
        self.pack() # Window is packed in its master.

        exitButton = Button(self, text="Run", command=self.clickrunButton)
        exitButton.pack()

    def clickrunButton(self):
        self.run() # Now this work
    
    def run(self):
        print('Something')

root = Tk()
app = Window(root)


# set window title
root.wm_title("Tkinter window")

# show window
root.mainloop()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.