I'm in the process of writing my first python program with a GUI just as practice. I have two listboxes that are packed in the same frame so they are side by side. I have one scroll bar and would like that one scrollbar to move both listboxes simultaneously since the data is related. Is this possible?
Keep in mind that this is my first program so if you have any tips please feel free to post them.
#!/usr/bin/python
from tkinter import *
import pickle
root = Tk()
root.title("Note Taker")
textframe = Frame(root)
listframe = Frame(root)
def Button1():
global newWindow
newWindow = Tk()
newWindow.title("New Window")
tframe = Frame(newWindow)
global text1
global text2
text1 = Entry(newWindow)
text2 = Entry(newWindow)
add = Button(newWindow, text="Add", command = Add)
add.grid(row=3, column=1)
text1.grid(row=0, column=1)
text2.grid(row=1, column=1)
itemName = Label(newWindow, text="Item Name")
itemName.grid(row=0, column=0)
numItem = Label(newWindow, text="Number of Items")
numItem.grid(row=1, column=0)
newWindow.mainloop()
def Add():
text1_contents = text1.get()
text2_contents = text2.get()
namebox.insert(END, text1_contents)
numbox.insert(END, text2_contents)
text1.delete(0,END)
text2.delete(0,END)
newWindow.destroy()
def Button3():
text_contents = text.get()
namebox.insert(END, text_contents)
text.delete(0,END)
def ReturnInsert(event):
Button3()
def DeleteCurrent(event):
listbox.delete(ANCHOR)
def CopyToText(event):
text.delete(0,END)
current_note = listbox.get(ANCHOR)
text.insert(0, current_note)
def Save():
f= file("notes.db", "wb")
notes = listbox.get(0, END)
pickle.dump(notes, f)
button1 = Button(textframe, text="Add Item", command = Button1)
button2 = Button(textframe, text="button2")
button3 = Button(textframe, text="button3", command = Button3)
text = Entry(textframe)
text.bind("<Return>", ReturnInsert)
scrollbar = Scrollbar(listframe, orient=VERTICAL)
namebox = Listbox(listframe, yscrollcommand=scrollbar.set)
namebox.bind("<Double-Button-3>", DeleteCurrent)
namebox.bind("<Double-Button-1>", CopyToText)
numbox = Listbox(listframe, yscrollcommand=scrollbar.set)
scrollbar.configure(command=namebox.yview)
text.pack(side=LEFT, fill=X, expand=1)
button1.pack(side=LEFT)
button2.pack(side=LEFT)
button3.pack(side=LEFT)
namebox.pack(side=LEFT, fill=BOTH, expand=1)
numbox.pack(side=LEFT, fill=BOTH, expand=1)
scrollbar.pack(side=RIGHT, fill=Y)
textframe.pack(fill=X)
listframe.pack(fill=BOTH, expand=1)
root.geometry("600x400")
try:
f = file("notes.db", "rb")
notes = pickle.load(f)
for item in notes:
listbox.insert(END, item)
f.close()
except:
pass
root.mainloop()