Python TkInter设置来自外部函数的输入文本
我正在制作一个GUI,为了整理它,我正在研究将核心功能拉到外部脚本中的可能性,并让主GUI调用它 外部模块需要能够读取小部件数据并对其进行操作 例如: 我有一个脚本,它有GUI的基础,运行时会打开它 我有另一个脚本,在一个文件夹中,将包含使GUI功能的模块 主GUI脚本需要能够调用这些模块/函数,并且它们需要能够编辑小部件 我做了一些研究,但没有任何帮助,大多数问题都是关于主脚本中的函数,我已经知道如何做到这一点 主GUI脚本Python TkInter设置来自外部函数的输入文本,python,user-interface,tkinter,python-module,tkinter-entry,Python,User Interface,Tkinter,Python Module,Tkinter Entry,我正在制作一个GUI,为了整理它,我正在研究将核心功能拉到外部脚本中的可能性,并让主GUI调用它 外部模块需要能够读取小部件数据并对其进行操作 例如: 我有一个脚本,它有GUI的基础,运行时会打开它 我有另一个脚本,在一个文件夹中,将包含使GUI功能的模块 主GUI脚本需要能够调用这些模块/函数,并且它们需要能够编辑小部件 我做了一些研究,但没有任何帮助,大多数问题都是关于主脚本中的函数,我已经知道如何做到这一点 主GUI脚本 import os, sys, ttk, pyodbc from
import os, sys, ttk, pyodbc
from Tkinter import *
import Utils.Common as Common
class GUI:
def __init__(self, *args):
self.style = ttk.Style()
font = "TkDefaultFont"
root.title(uiTitle)
root.iconbitmap(uiIcon)
root.geometry(uiGeometry)
self.connectBtn = ttk.Button(root, width=65)
self.connectBtn.configure(text="Connect", command=Common.connectCleardox)
self.connectBtn.grid(row=0, columnspan=4)
self.exampleEnt = Entry(root, width=30)
self.exampleEnt.grid(row=1, columnspan=4)
if __name__ == '__main__':
root = Tk()
GUI(root)
root.mainloop()
Utils/Common.py
import tkMessageBox
from Tkinter import *
sys.path.insert(0, r'\\cd3\IT\Python\#PythonLibraries\Modules')
from CommonDB import Database
def connectCleardox():
try:
cleardoxConnection = Database.ConnectDatabase(Database(r"\\cd3\IT\Python\#PythonLibraries\ConfigFiles\Cleardox\Cleardox ConfigFile.json"))
exampleEnt.insert(0, 'Success') #The widget from the GUI
except Exception as e:
tkMessageBox.showerror('uiTitle', "Database connection failed.\n\n%s" % (e))
exampleEnt.insert(0, 'Fail') #The widget from the GUI
return
请让我知道,如果我是太含糊,或没有给予足够的描述
谢谢大家抽出时间
Dylan.可能是重复的所以,你的确切问题是?也许您可以看看MVC架构模式,我认为它可以帮助您更全面地了解系统并正确地构造应用程序?您需要帮助的确切问题是什么?您的utils文件夹是否包含
\uuuu init\uuuuu.py
文件?@danlor我确切的问题是如何从外部模块操作Tkinter对象。