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

2024-10-02 10:33:09 发布

您现在位置:Python中文网/ 问答频道 /正文

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

当使用start函数启动set_name函数时,调用该函数

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):
        ...

Tags: 函数textnamefrompyimportselfmain

热门问题