繁体   English   中英

如何在不导入主文件的情况下从另一个文件调用 function?

[英]How can I call a function from another file without importing the main file?

我想知道如何为我的 GUI 项目调用 function。 这是我的 main.py 文件,其中有一个我想调用的set_name function。 例如: a=Thread(target='set_name')

启动 function 时调用set_name function 用于启动它。

from tkinter import *
import set_item
root=Tk()
def set_cordinate (event,A):
    set_item.Sett.set_name(A)
def get_cordinate(t):
    print(t)
b=Button(root,text='Hi',border=0,command=lambda:set.Set.call_modify('Button b clicked')).pack
co=Button(root,text='Get cordinates',command=lambda=set_cordinate((100,200)))

这是 set_item.py

from tkinter import *
root=Tk()
class Sett:
    def __init__(self):
        ...
    def set_cordinate(self,ele):
        e=Button(root,text='Get cordinates').pack()
        e.bind('<Button-3>',??)#Here I should call get_cordinate of main.py file and pass ele into it.
        #Instead of ?? what should I write can anybody please tell me             
    def call_modify(self,name):
        ...

您是否阅读过有关模块的 python 文档? 如果没有,那么我认为您应该检查一次:-),我认为它会对您有所帮助! Python 模块文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM