I am writing a program for a GUI based plotter, using matplotlib and tkinter I have an upper window I have added I want to execute a function and after clicking the button I want to exit the upper window. Is this possible?
The problem I face is that I have used an upper window which needs to be called from the main window. So I defined a function in which this upper window is included. If I define another function which can perform several operations, then it can not recognize the upper window. I can define it under a class, but it is unsure if it works. Here is a part of my code that includes a high-level window
def plt_options (arg):. Global lg_var, col_var, line_type_var, marker_var plt_opt = high level (application) lg_var = StringVar (none) lg_text = label (plt_opt, text = 'legend'). Grid (line = 0, column = 0, sticky = e) lg_box = entry (plt_opt, textvar = lg_var) lg_box.grid (line = 0, column = 1, sticky = w) col_var = StringVar (none) col_var.set ('Blue') col_text = label (plt_opt, text = 'color'). Grid (line = 1, column = 0) col_chooser = OptionMenu (plt_opt, col_var, 'blue', 'green', 'red', 'cyan', 'magneta', 'yellow', 'black', 'white' ) Col_chooser.grid (line = 1, column = 1) line_type_var = StringVar (none) line_type_var.set ('solid') line_type_text = label (plt_opt, text = 'line type'). Line_chooser = OptionMenu (plt_opt, line_type_var, 'solid', 'dashed', 'dotted', 'dash-dotted', 'none') line_chooser.grid (line = 2, grid (line = 2, Column = 1) marker_var = StringVar (none) marker_var.set ('none') marker_text = label (plt_opt, text = 'marker'). The grid (line = 3, column = 0) marker_chooser = option menu (plt_opt, mar, Ker_var, 'plus', 'dot', 'circle', 'star', 'pentagon', 'squire', 'cross', 'diamond' , 'Hexagon', 'triangle') marker_chooser.grid (line = 3, column = 1) ok_btn = button (plt_opt, text = 'OK', command = test) .grid () < / Div>
The buttons are designed exactly for this. Typically you will define a function or method that you want, then assign that method to the command button: import as import tkMessageBox Class SampleApp (tk.Tk): def __init __ (self): tk.Tk .__ init __ (self) button = vaccines. Button (text = "press me!", Command = self.n_button) button.pack () def on_button (auto): TkMessageBox.showinfo (message = "good bye!") Self.destroy () app = sample app () App.manlow ()
Comments
Post a Comment