Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23189

Why isnt the graph redrawn

$
0
0

Im making an app, where users can collide blocks, and they get graphs of the initial variable against the final velocity, i want the user to be able to switch which graph they want by clicking on different labels.

def Func__DoubleResults__():  global _Type1,_Type2,_Type3,_Type4  try:    Win__DoubleGraphsWindow__.destroy()    Win__FinalValuesWindow__.destroy()  except:    pass  draw_blocks(t=1, side1=float(mass1Entry.get()), side2=float(mass2Entry.get()))  draw_blocks(t=2, side3=float(mass3Entry.get()), side4=float(mass4Entry.get()))  _ScreenWidth = main_gui.winfo_screenwidth()  _ScreenHeight = main_gui.winfo_screenheight()  _WindowWidth = main_gui.winfo_width()  _WindowHeight = main_gui.winfo_height()  _NewX = 0  _NewY = 0  _GraphsWindowX = _NewX + main_gui.winfo_width() + 10  Var_GraphsWindowWidth = main_gui.winfo_width() / 2  Var_GraphsWindowHeight = main_gui.winfo_height()   main_gui.geometry("{}x{}+{}+{}".format(_WindowWidth, _WindowHeight, _NewX, _NewY))  _TitleBarHeight = main_gui.winfo_rooty()-main_gui.winfo_y()  Win__FinalValuesWindow__ = Tk()  Win__FinalValuesWindow__.geometry("{}x{}+{}+{}".format(round(_WindowWidth +10), _ScreenHeight - _WindowHeight - 40 -50 - _TitleBarHeight , _NewX, _NewY + _WindowHeight+_TitleBarHeight))  Win__FinalValuesWindow__.title("Final Values")  Win__FinalValuesWindow__.configure(bg=bg_color)  Win__DoubleGraphsWindow__ = Tk()  Win__DoubleGraphsWindow__.geometry("{}x{}+{}+{}".format(round(Var_GraphsWindowWidth),Var_GraphsWindowHeight+ _ScreenHeight - _WindowHeight - 40 -50 - _TitleBarHeight,_GraphsWindowX,_NewY))  Win__DoubleGraphsWindow__.title("Graphs")  Win__DoubleGraphsWindow__.configure(bg=bg_color)  global Var_Axs1,Var_Axs2,Var_Fig1,Var_Fig2,Wgt__GraphsFor1And2,Wgt__GraphsFor3And4  Var_Fig1,Var_Axs1 = plt.subplots(1,2)  Var_Fig1.set_figheight(2.48)  Var_Fig1.set_figwidth(5.5)  Var_Fig2,Var_Axs2 = plt.subplots(1,2)  Var_Fig2.set_figheight(2.48)  Var_Fig2.set_figwidth(5.5)  n = Win__DoubleGraphsWindow__.winfo_height()  print("Adadadadad",Var_GraphsWindowHeight+ _ScreenHeight - _WindowHeight - 40 -50 - _TitleBarHeight)  Wgt__GraphsFor1And2 = Frame(master = Win__DoubleGraphsWindow__,width=round(Var_GraphsWindowWidth) - 20,height=round(Win__DoubleGraphsWindow__.winfo_height()/4),bg=bg_color)  Wgt__GraphsFor1And2.pack(side="top")  Wgt__GraphsFor3And4 = Frame(master=Win__DoubleGraphsWindow__,width=round(Var_GraphsWindowWidth) - 20,height=round(Win__DoubleGraphsWindow__.winfo_height()/4),bg=bg_color)  Wgt__GraphsFor3And4.pack(side="bottom")  Wgt__Graphs1 = FigureCanvasTkAgg(Var_Fig1,master = Wgt__GraphsFor1And2)  Wgt_Graphs2 = FigureCanvasTkAgg(Var_Fig2,master=Wgt__GraphsFor3And4)  Var_Fig1.tight_layout()  Var_Fig2.tight_layout()  Wgt__Graphs1.get_tk_widget().pack(fill=BOTH,expand=True)  Wgt_Graphs2.get_tk_widget().pack(fill=BOTH,expand=True)  def Func__PlotGraph1__(type = 0):    print(type)    for ax in Var_Axs1:      ax.cla()    Var_YList = []    Var_XList = [i/100 for i in range(0,101)] if type == "COR" else (list(range(0,101)) if type == "INITIAL" else list(range(1,101)))    m1 = float(mass1Entry.get())    m2 = float(mass2Entry.get())    e = float(cOREntry.get())    v1 = float(initial1Entry.get())    v2 = -1 * float(initial2Entry.get())        if type ==  "INITIAL":      for n in Var_XList:        Var_YList.append((((m1 * n) + (m2 * v2) + (m2 * e * (v2 - n))) / (m1 + m2)))    elif type == "MASS":      for n in Var_XList:        Var_YList.append(((n * v1) + (m2 * v2) + (m2 * e * (v2 - v1))) / (n + m2))    else:      for i in Var_XList:        Var_YList.append(round((((m1 * v1) + (m2 * v2) + (m2 * i * (v2 - v1))) / (m1 + m2)),2))    print(Var_XList,Var_YList)    Var_Axs1[0].plot(Var_XList,Var_YList)    Var_Axs1[0].set_xlabel(type,fontsize=6)    Var_Axs1[0].set_title(type,fontsize=6)  def Func__ChangeType__(event):    name = event.widget    name = list(Local_Vars.keys())[list(Local_Vars.values()).index(name)]    _TypesDict = {"Wgt__Initial1Choice" : "INITIAL","Wgt__Initial2Choice" : "INITIAL","Wgt__Initial3Choice" : "INITIAL","Wgt__Initial4Choice" : "INITIAL","Wgt__Mass1Choice" : "MASS","Wgt__Mass2Choice" : "MASS","Wgt__Mass3Choice" : "MASS","Wgt__Mass4Choice" : "MASS","Wgt__Restitution1Choice" : "COR","Wgt__Restitution2Choice" : "COR","Wgt__Restitution3Choice" : "COR","Wgt__Restitution4Choice" : "COR",    }    _TypeReferenece = {"Wgt__Initial1Choice" : _Type1,"Wgt__Initial2Choice" : _Type2,"Wgt__Initial3Choice" : _Type3,"Wgt__Initial4Choice" : _Type4,"Wgt__Mass1Choice" : _Type1,"Wgt__Mass2Choice" : _Type2,"Wgt__Mass3Choice" : _Type3,"Wgt__Mass4Choice" : _Type4,"Wgt__Restitution1Choice" : _Type1,"Wgt__Restitution2Choice" : _Type2,"Wgt__Restitution3Choice" : _Type3,"Wgt__Restitution4Choice" : _Type4,    }    _TypeReferenece[name] = _TypesDict[name]    print(_TypeReferenece[name],_TypesDict[name])    Func__PlotGraph1__(type=_TypesDict[name])  Wgt__Block1Choices = Frame(Win__DoubleGraphsWindow__,bg=bg_color,height=170,width=273, padx=20, pady=20)  Wgt__Initial1Choice = Label(master=Wgt__Block1Choices,text="As Initial Velocity Changes",bg=bg_color,highlightthickness=0)  Wgt__Mass1Choice = Label(master=Wgt__Block1Choices,text="As Mass Changes",bg=bg_color,highlightthickness=0)  Wgt__Restitution1Choice = Label(master=Wgt__Block1Choices,text="As Restitution Changes",bg=bg_color,highlightthickness=0)  Wgt__Initial1Choice.bind("<Button-1>",lambda x: (Func__ChangeType__(event=x)))  Wgt__Mass1Choice.bind("<Button-1>",lambda x:(Func__ChangeType__(event=x)))  Wgt__Restitution1Choice.bind("<Button-1>",lambda x:(Func__ChangeType__(event=x)))  global Var_Block1List,Wgt__Entry1,Wgt__Entry2,Wgt__Entry3,Wgt__Entry4,Wgt__FinalOut1,Wgt__FinalOut2,Wgt__FinalOut3,Wgt__FinalOut4  Var_Block1List = [Wgt__Initial1Choice,Wgt__Mass1Choice,Wgt__Restitution1Choice]  global Wgt__Entry1,Wgt__Entry2,Wgt__Entry3,Wgt__Entry4,Wgt__FinalOut1,Wgt__FinalOut2,Wgt__FinalOut3,Wgt__FinalOut4  Wgt__Entry1 = Entry(master=Wgt__Block1Choices)  Wgt__Entry1.insert(0,"Initial Value . . .")  Wgt__Entry1.bind("<FocusIn>",lambda x:Wgt__Entry1.delete(0,END) if Wgt__Entry1.get() == "Initial Value . . ." else Wgt__Entry1.get())  Wgt__Entry1.bind("<FocusOut>",lambda x:Wgt__Entry1.insert(0,"Initial Value . . .") if Wgt__Entry1.get() == "" else Wgt__Entry1.get())  Wgt__Entry1.bind("<Return>",lambda x :Func__Output1__(event=x))  Wgt__FinalOut1 = Entry(master=Wgt__Block1Choices)  Wgt__FinalOut1.insert(0,"Final Value . . .")  Wgt__FinalOut1.bind("<FocusIn>",lambda x:Wgt__FinalOut1.delete(0,END) if Wgt__FinalOut1.get() == "Final Value . . ." else Wgt__FinalOut1.get())  Wgt__FinalOut1.bind("<FocusOut>",lambda x:Wgt__FinalOut1.insert(0,"Final Value . . .") if Wgt__FinalOut1.get() == "" else Wgt__FinalOut1.get())  Wgt__Initial1Choice.pack(side="top",anchor="w")  Wgt__Mass1Choice.pack(side="top" ,anchor="w")  Wgt__Restitution1Choice.pack(side="top",anchor="w")  Wgt__Entry1.pack(side="top",anchor="center",pady=(3,0))  Wgt__FinalOut1.pack(side="top",anchor="center")  Wgt__Block1Choices.place(x=0,y=239)

I tried to do just the clear method,and that didnt do anything, meaning that the plot was not being cleared, i looked online for answers and couldnt find anything.This is part of the function that makes the new windows, that contain the graphs


Viewing all articles
Browse latest Browse all 23189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>