Feb-16-2020, 11:23 PM
Ok Jionni
Lets make a simple application. By activating the button the app will multiply your listbox selection witch is stored in the variable 'b' with the constant PI:
Lets make a simple application. By activating the button the app will multiply your listbox selection witch is stored in the variable 'b' with the constant PI:
import tkinter as tk # Constants for the geometry of the main window APP_XPOS = 100 APP_YPOS = 100 APP_WIDTH = 300 APP_HEIGHT = 300 APP_TITLE = "Simple Applikation" PI = 3.1415 # Variables b = 0 items_for_listbox = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # Functions def select(event): global b b = int(mylistbox.get(tk.ANCHOR)) selected_var.set(b) def calculate(): global b result = b * PI result_var.set(result) # GUI # App window app_win = tk.Tk() app_win.title(APP_TITLE) app_win.wm_geometry("%dx%d+%d+%d" % (APP_WIDTH, APP_HEIGHT, APP_XPOS, APP_YPOS)) # Main container embeded in the app window # Container for all of the app widgets main_frame = tk.Frame(app_win) main_frame.pack(expand=tk.YES, fill=tk.BOTH) # Label to show your listbox selection selected_var = tk.StringVar() tk.Label(main_frame, textvariable=selected_var, font=('times', 30, 'bold') ).pack(expand=tk.YES) selected_var.set("No selection") # Label to show your calculated result result_var = tk.StringVar() tk.Label(main_frame, textvariable=result_var, font=('times', 30, 'bold') ).pack(expand=tk.YES) result_var.set("No result") # Container for the listbox & scrollbar (embeded in the main frame) listbox_frame = tk.Frame(main_frame) listbox_frame.pack(expand=tk.YES) mylistbox = tk.Listbox(listbox_frame, height=5, width=25, font=('times',13)) mylistbox.bind('<<ListboxSelect>>', select) mylistbox.grid(row=0, column=0) mylistbox.insert(tk.END, *items_for_listbox) scroll = tk.Scrollbar(listbox_frame, orient=tk.VERTICAL) # the allignment of the scrollbar mylistbox["yscrollcommand"] = scroll.set # link the list with the scroll scroll["command"] = mylistbox.yview # link the scroll with the scroll scroll.grid(row=0, column=1, sticky=tk.N+tk.S) #sticky=N+S+E) # Button to launch a calculation tk.Button(main_frame, text="Calculate (Listbox selection * PI)", command=calculate).pack(expand=tk.YES) app_win.mainloop()wuf :-)