I've had a little dilemma and I think that it might be the same for a few people(hopefully). The following code gets names from a text file in the same folder, then prints them out in a frame. Unfortunately I don't know how to add a scrolling functionality into just this frame (nameframe). I need this code so that when you have a long list of names, all the names can be seen. Currently you can only see half of the names. I also would like the buttons to be the same size.
from tkinter import *
import time
import datetime
import re
root = Tk()
root.title("Attendence Register")
root.geometry('1350x650+0+0')
root.resizable(False, False)
nameframe = Frame(root, height=650, width=300)
nameframe.pack(side='left')
saveframe = Frame(root, height=650, width=300)
saveframe.pack(side='right')
outlist = []
def saveDataPresent(line):
presentcount[line] += 1
if presentcount[line] %2 == 1:
present[line].configure(bg='#ff4dd2')
line = (line + ' is present')
outlist.append(line)
#print(outlist)
else:
present[line].configure(bg='#66ff66')
line = (line + ' is present')
outlist.remove(line)
#print(outlist)
def saveDataAbsent(line):
absentcount[line] += 1
if absentcount[line] % 2 == 1:
absent[line].configure(bg='#ff4dd2')
line = (line + ' is absent')
outlist.append(line)
#print(outlist)
else:
absent[line].configure(bg='#ff6666')
line = (line + ' is absent')
outlist.remove(line)
#print(outlist)
def saveDataIll(line):
illcount[line] += 1
if illcount[line] % 2 == 1:
ill[line].configure(bg='#ff4dd2')
line = (line + ' is ill')
outlist.append(line)
#print(outlist)
else:
ill[line].configure(bg='#ffa31a')
line = (line + ' is ill')
outlist.remove(line)
#print(outlist)
def saveDataHoliday(line):
holidaycount[line] += 1
if holidaycount[line] % 2 == 1:
holiday[line].configure(bg='#ff4dd2')
line = (line + ' is holiday')
outlist.append(line)
#print(outlist)
else:
holiday[line].configure(bg='light blue')
line = (line + ' is holiday')
outlist.remove(line)
#print(outlist)
def saveData():
now = datetime.datetime.now()
now = str(now)
dire = 'logs/'
now = dire + now
now = re.sub(':', '', now)
now += '.txt'
log = open(now, "w+")
log.close()
log = open(now, "a")
for i in outlist:
i = (i + '\n')
log.write(i)
log.close()
text = open('names.txt','r')
line = text.readline()
count = 0
present = {}
absent = {}
ill = {}
holiday = {}
presentcount = {}
absentcount = {}
illcount = {}
holidaycount = {}
for line in text:
count+= 1
name = Label(nameframe, text=line)
name.grid(row=count, column = 0)
presentcount[line] = 0
absentcount[line] = 0
illcount[line] = 0
holidaycount[line] = 0
present[line] = Button(nameframe, text='/', pady = 20, padx=20, bg ='#66ff66', command=lambda line=line: saveDataPresent(line))
present[line].grid(row=count, column = 2)
holiday[line] = Button(nameframe, text='H', pady=20, padx=20, bg='light blue', command=lambda line=line: saveDataHoliday(line))
holiday[line].grid(row=count, column=3)
ill[line] = Button(nameframe, text='ill', pady=20, padx=20, bg ='#ffa31a', command=lambda line=line: saveDataIll(line))
ill[line].grid(row=count, column=4)
absent[line] = Button(nameframe, text='NA', pady=20, padx=20, bg ='#ff6666', command=lambda line=line: saveDataAbsent(line))
absent[line].grid(row=count, column=5)
savebut = Button(saveframe, text='Save', pady = 20, padx=20, command=saveData)
savebut.pack()
root.mainloop()
Thanks for any help I hope my question is clear. In summary, I would like to know how to add a functioning scroll bar, or atleast something to help to be able to see all the names. This scroll bar should only affect nameframe. To show my situation more clearly: Image of the frame cutting
This is the sort of thing that I'm looking for:
nameframe = Frame(root, height=650, width=300)
nameframe.pack(side='left')
vsb = Scrollbar(orient="vertical", command=nameframe.yview)
nameframe.configure(yscrollcommand=vsb.set)
saveframe = Frame(root, height=650, width=300)
This commes up with the error: 'Frame' object has no attribute 'yview' saveframe.pack(side='right')