Reputation: 88
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
Upvotes: 1
Views: 65
Reputation: 2644
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)
Upvotes: 1