Python Forum
Code fails on Mac, works on Windows and Raspberry Pi
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code fails on Mac, works on Windows and Raspberry Pi
#1
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

#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()
Reply


Messages In This Thread
Code fails on Mac, works on Windows and Raspberry Pi - by eugenedakin - May-28-2018, 12:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Listbox search code partially works chesschaser 9 3,847 May-05-2020, 01:08 PM
Last Post: chesschaser
  [Tkinter] Tkinter GUI works on Windows but not on Ubuntu danbei 8 9,124 Jun-27-2017, 08:03 PM
Last Post: danbei
  popup message box code runs in Windows, but not in Linux Luke_Drillbrain 13 14,926 May-10-2017, 01:05 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020