如何在 python 中从此 GUI 调用另一个“.py”?
How can I call another ".py" from this GUI in python?
我正在尝试使用下面这个 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()
任何人都可以帮助我吗?
tks
您可以导入另一个 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)
我正在尝试使用下面这个 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()
任何人都可以帮助我吗? tks
您可以导入另一个 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)