1

I'm trying to call another py with a button in this GUI below. How can I create a button that calls another py?

The other py is in: Y:\path\python_robos\Controle_teste.py

import tkinter
janela = tkinter.Tk()
janela.title("Controle dos Robôs - Mercado de Capitais / Diretoria de Securitização")

janela.geometry("1000x500+100+100")

lb = Label(janela, text = "Para rodar os robôs clique no botão abaixo.")
lb.place(x=10, y=20)

lb2 = Label(janela, text = "Robôs criados por Antonio Hildenberg com supervisão de Felipe Ribeiro. Set/2019")
lb2.place(x=10, y=470)

janela.mainloop()

can anydoby help me? tks

Felipe Ribeiro
  • 84
  • 1
  • 10
  • Maybe this is what you want. [How can I make one python file run another?](https://stackoverflow.com/questions/7974849/how-can-i-make-one-python-file-run-another) – Jack Sep 27 '19 at 18:44

1 Answers1

1

You can import the other Python file.

As an example if you have a python file named constants.py, in the same directory, you can import it by writing import constants as const.

You can now use its classes, methods and variables with const.MY_CONSTANT.

Edit: Here's how you can create a button in tkinter and assign a click event listener to it.

"""Create Submit Button"""
submitButton = Button(master, command=self.buttonClick, text="Submit")
submitButton.grid()

def buttonClick(self):
    """ handle button click event and output text from entry area"""
    print('hello')    # do here whatever you want
    const.MY_METHOD(my_variable)
Keimeno
  • 2,512
  • 1
  • 13
  • 34