我正在尝试使用下面这个 GUI 中的按钮调用另一个 py。如何创建一个调用另一个 py 的按钮?
另一个 py 位于: 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()
任何人都可以帮助我吗? 谢了
最佳答案
您可以导入其他 Python 文件。
例如,如果您有一个名为 constants.py
的 Python 文件,在同一目录中,您可以通过编写 import Constants as const
来导入它。
您现在可以通过 const.MY_CONSTANT
使用它的类、方法和变量。
编辑: 下面介绍了如何在 tkinter 中创建按钮并为其分配单击事件监听器。
"""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)
关于python - 如何在 python 中从这个 GUI 调用另一个 ".py"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58139657/