May-28-2018, 12:49 AM
(This post was last modified: May-28-2018, 12:49 AM by eugenedakin.)
Hello Everyone,
This is my first time posting in this forum - thanks for your patience. Here is a listing of a simple ScrollBar being attached to a Listbox with a Frame. This example works well on Windows 10, Raspberry Pi Stretch, and outputs many items on Mac High Sierra (10.13.4). The code is supposed to show a single message box per mouse click with the selected item number that was chosen by the user. On Mac it shows the number and then repeats a random amount of times (3-5 so far). Is there something specific that I need to do to make this work on Mac, or is this a possible bug?
Thanks :)
Eugene
Edit: All code is executed in IDLE 3.6.x
This is my first time posting in this forum - thanks for your patience. Here is a listing of a simple ScrollBar being attached to a Listbox with a Frame. This example works well on Windows 10, Raspberry Pi Stretch, and outputs many items on Mac High Sierra (10.13.4). The code is supposed to show a single message box per mouse click with the selected item number that was chosen by the user. On Mac it shows the number and then repeats a random amount of times (3-5 so far). Is there something specific that I need to do to make this work on Mac, or is this a possible bug?
Thanks :)
Eugene
Edit: All code is executed in IDLE 3.6.x
#Import the tkinter library
from tkinter import *
from tkinter import messagebox
from tkinter import Listbox
from tkinter import Scrollbar
#Function Definition
def CurSelet(evt):
value=str((Listbox1.get(ANCHOR)))
messagebox.showinfo("Selection","You selected: " + str(value))
#Create a window
window=Tk()
#Change the Window Title
window.title("Example2-5")
#Change the dimension of the window
window.geometry("300x200")
#Add a label
Label1=Label(window, text="View the listbox and click on a number",justify=CENTER)
Label1.pack(side="top")
#Add the Frame for alignment and then
#the Listbox and Scrollbar widgets
Frame1=Frame(window)
Frame1.pack(side="top")
Listbox1 = Listbox(Frame1)
Listbox1.pack(side="left",fill=Y)
ScrollBar1=Scrollbar(Frame1,orient=VERTICAL)
ScrollBar1.config(command=Listbox1.yview)
ScrollBar1.pack(side=RIGHT,fill=Y)
Listbox1.yscrollcommand=ScrollBar1.set
#Populate the listbox with data
for i in range(20):
Listbox1.insert(END, str(i))
Listbox1.bind("<<ListboxSelect>>", CurSelet) #Listbox Selection
window.mainloop()
