I am a beginner playing around with Python and Tkinter. I wrote this program to draw random names given the students in my classes. I tried to follow PEP 8, but I was wondering if there are any stylistic problems here and also if there is any way to condense the code without affecting the working of the program (as I've finally gotten it to work like I want it to.)
from random import *
from Tkinter import *
class App:
def __init__(self, master):
self.count_s7=0
self.count_s8=0
self.count_m10=0
self.m=[]
self.frame = Frame(master, height=500, width=500)
self.frame.grid()
self.Results = Message(self.frame, text="", width=400, font="Courier, 32")
self.Results.grid(row=1, column=1)
self.b1 = Button (self.frame, text = "Get Random Name: Science 7", width=50,
command = self.s7_Names, bg="#6ddd58")
self.b1.grid(row=2, column=1)
self.b2 = Button (self.frame, text = "Get Random Name: Science 8",width=50,
command = self.s8_Names, bg="#75c0d2")
self.b2.grid(row=3, column=1)
self.b3 = Button (self.frame, text = "Get Random Name: Math 10",width=50,
command = self.m10_Names, bg="#ffb9ec")
self.b3.grid(row=4, column=1)
self.Quit = Button (self.frame, text = "Quit", command=self.frame.quit)
self.Quit.grid (row=5, column=1)
def get_names(self, roster, i):
words = roster[i]
self.Results.config(text=words)
def draw_names(self, roster, count):
if count == 0:
self.mixed = sample(roster, len(roster))
self.get_names(self.mixed, count)
count +=1
elif 0 < count < len(roster):
self.get_names(roster, count)
count +=1
else:
count = 0
self.mixed = sample(roster, len(roster))
self.get_names(self.mixed, self.count)
self.count_s7 +=1
def s7_Names(self):
s7 = ['Name1', 'Name2', 'Name3', 'Name4', 'Name5', 'Name6','Name7',
'Name 8', 'Name9','Name10', 'Name11','Name12','Naome13']
self.draw_names(s7, self.count_s7)
def s8_Names(self):
s8 = ['Kid1','Kid2','Kid3','Kid4','Kid5','Kid6','Another kid']
self.draw_names(s8, self.count_s8)
def m10_Names(self):
m10 = ['Student1', 'Student2', 'Student3', 'Student4', 'Student5'
'Student6', 'Student7', 'Student8', 'Student9']
self.draw_names(m10, self.count_m10)
root=Tk()
root.title("Random Names")
app = App(root)
root.mainloop()
root.destroy()