将脚本链接回Tkinter GUI Python
我已经创建了一个Tkinter GUI,它从一个文本文件中获取数据,并根据一些用户输入进行打印。从外部脚本调用函数并将绘图返回GUI时遇到问题 一般来说,我是python的初学者,所以如果您发现任何不好的实践/糟糕的解释,请告诉我 文件定义: py:包含GUI外壳/小部件/按钮等 Plot.py:包含打印算法 如果我将GUI和PLot算法组合在同一个脚本中,它工作得很好,因此我不关心实际的算法/循环,只是当我将其分离时,我在两者之间调用时遇到了问题-尽管我尝试使用google/stackexchange/youtube,但我不确定我是否完全理解这一点 GUI.py(相关位): “PlotonName(Ans)”和“PlotonSeparated(Ans)”旨在将“Ans”传递给我的外部“Plot.py”(我已导入) Plot.py:将脚本链接回Tkinter GUI Python,python,python-2.7,tkinter,Python,Python 2.7,Tkinter,我已经创建了一个Tkinter GUI,它从一个文本文件中获取数据,并根据一些用户输入进行打印。从外部脚本调用函数并将绘图返回GUI时遇到问题 一般来说,我是python的初学者,所以如果您发现任何不好的实践/糟糕的解释,请告诉我 文件定义: py:包含GUI外壳/小部件/按钮等 Plot.py:包含打印算法 如果我将GUI和PLot算法组合在同一个脚本中,它工作得很好,因此我不关心实际的算法/循环,只是当我将其分离时,我在两者之间调用时遇到了问题-尽管我尝试使用google/stackexch
def Plotonsame(s):
#prepare canvas
fig=figure.Figure(figsize=(8,6))
a=fig.add_subplot(111)
for option in s:
#s=Ans[option]
self.Pro_txt.insert(END,s[option])
#Plot the series
a.plot(s[option], label=option)
a.legend(bbox_to_anchor=(0,1.02,1,.102),loc=3,ncol=2,borderaxespad=0,prop={'size':10})
app1.dataPlot=FigureCanvasTkAgg(fig,master=app1)
app1.dataPlot.get_tk_widget().grid(row=1,rowspan=m,column=15,sticky="nsew")
def Plotseparately(s):
s=self.Ans
length=len(s) #count the number of options
if length==1:
j=1 #number of rows
i=1 #number of columns
if length==2:
j=1
i=2
elif length in (3,4):
j=2
i=2
elif length in (5,6):
j=2
i=3
elif length in (7,8,9):
j=3
i=3
canvaswidth=9
canvasheight=7
index=0
fig=figure.Figure(figsize=(canvaswidth,canvasheight))
for option in s: #create subplots within the defined canvas 'fig'
index+=1 #iterates over number of subplots
a=fig.add_subplot(j,i,index) #adds the individual subplots
self.Pro_txt.insert(END,s) #insert text(Ans[option]) into Processed window
a.plot(self.Ans[option],label=option) #Plot the series
a.legend(bbox_to_anchor=(0,1.02,1,.102),loc=3,ncol=2,prop={'size':7}) #adds the legend for each subplot
dataPlot=FigureCanvasTkAgg(fig,master=self) #brings all plots together
dataPlot.get_tk_widget().grid(row=1,rowspan=30,column=15,sticky="nsew") #draws the plot frame with data etc
def Plotonsame(s):
#prepare canvas
fig=figure.Figure(figsize=(8,6))
a=fig.add_subplot(111)
for option in s:
#s=Ans[option]
self.Pro_txt.insert(END,s[option])
#Plot the series
a.plot(s[option], label=option)
a.legend(bbox_to_anchor=(0,1.02,1,.102),loc=3,ncol=2,borderaxespad=0,prop={'size':10})
app1.dataPlot=FigureCanvasTkAgg(fig,master=app1)
app1.dataPlot.get_tk_widget().grid(row=1,rowspan=m,column=15,sticky="nsew")
def Plotseparately(s):
s=self.Ans
length=len(s) #count the number of options
if length==1:
j=1 #number of rows
i=1 #number of columns
if length==2:
j=1
i=2
elif length in (3,4):
j=2
i=2
elif length in (5,6):
j=2
i=3
elif length in (7,8,9):
j=3
i=3
canvaswidth=9
canvasheight=7
index=0
fig=figure.Figure(figsize=(canvaswidth,canvasheight))
for option in s: #create subplots within the defined canvas 'fig'
index+=1 #iterates over number of subplots
a=fig.add_subplot(j,i,index) #adds the individual subplots
self.Pro_txt.insert(END,s) #insert text(Ans[option]) into Processed window
a.plot(self.Ans[option],label=option) #Plot the series
a.legend(bbox_to_anchor=(0,1.02,1,.102),loc=3,ncol=2,prop={'size':7}) #adds the legend for each subplot
dataPlot=FigureCanvasTkAgg(fig,master=self) #brings all plots together
dataPlot.get_tk_widget().grid(row=1,rowspan=30,column=15,sticky="nsew") #draws the plot frame with data etc