Skip to main content
Indent code that is meant to be within the class
Source Link
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()    
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()    
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()    
shorten body
Source Link

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 = ['Esther'['Name1', 'Fatu''Name2', 'Osobie''Name3', 'Shannon''Name4', 'Ben''Name5', 'Kingsley','Eunhye''Name6', 'Jogi''Name7',
          'Sargis','Ethan', 'Stephane','Name 'Rachel'8', 'Naomi''Name9', 'Emma''Name10',
          'Dongmin','Stijn''Name11', 'Sydney''Name12','Jireh']'Naome13']
    self.draw_names(s7, self.count_s7)
        

def s8_Names(self):
    s8 = ['Dueng', 'Jacob', 'Hannah H.', 'Abbie', 'Sosha', 'Daniella', 'Mathias',
          'Hannah M.'['Kid1','Joanina''Kid2', 'Vanessa''Kid3',  'Ezra''Kid4', 'Zoe''Kid5', 'James''Kid6','Another 'Ariela']kid']
    self.draw_names(s8, self.count_s8)

def m10_Names(self):
    m10 = ['RoseAnna', 'Rahim', 'Dominic'['Student1', 'Wendy''Student2', 'Beatrix''Student3', 'Junghee''Student4', 'Deborah','Student5'
          'Student6', 'Agasha''Student7', 'Landon']'Student8', 'Student9']
    self.draw_names(m10, self.count_m10)
      
     

    

root=Tk()
root.title("Random Names")
app = App(root)
root.mainloop()
root.destroy()    

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 = ['Esther', 'Fatu', 'Osobie', 'Shannon', 'Ben', 'Kingsley','Eunhye', 'Jogi',
          'Sargis','Ethan', 'Stephane', 'Rachel', 'Naomi', 'Emma',
          'Dongmin','Stijn', 'Sydney','Jireh']
    self.draw_names(s7, self.count_s7)
        

def s8_Names(self):
    s8 = ['Dueng', 'Jacob', 'Hannah H.', 'Abbie', 'Sosha', 'Daniella', 'Mathias',
          'Hannah M.','Joanina', 'Vanessa',  'Ezra', 'Zoe', 'James', 'Ariela']
    self.draw_names(s8, self.count_s8)

def m10_Names(self):
    m10 = ['RoseAnna', 'Rahim', 'Dominic', 'Wendy', 'Beatrix', 'Junghee', 'Deborah',
           'Agasha', 'Landon']
    self.draw_names(m10, self.count_m10)
      
     

    

root=Tk()
root.title("Random Names")
app = App(root)
root.mainloop()
root.destroy()

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()    
deleted 43 characters in body; edited title
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

Simple Namename-Drawerdrawer using Python and Tkinter

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.) Any feedback would be appreciated.

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 = ['Esther', 'Fatu', 'Osobie', 'Shannon', 'Ben', 'Kingsley','Eunhye', 'Jogi',
          'Sargis','Ethan', 'Stephane', 'Rachel', 'Naomi', 'Emma',
          'Dongmin','Stijn', 'Sydney','Jireh']
    self.draw_names(s7, self.count_s7)
        

def s8_Names(self):
    s8 = ['Dueng', 'Jacob', 'Hannah H.', 'Abbie', 'Sosha', 'Daniella', 'Mathias',
          'Hannah M.','Joanina', 'Vanessa',  'Ezra', 'Zoe', 'James', 'Ariela']
    self.draw_names(s8, self.count_s8)

def m10_Names(self):
    m10 = ['RoseAnna', 'Rahim', 'Dominic', 'Wendy', 'Beatrix', 'Junghee', 'Deborah',
           'Agasha', 'Landon']
    self.draw_names(m10, self.count_m10)
      
     

    

root=Tk()
root.title("Random Names")
app = App(root)
root.mainloop()
root.destroy()    

Simple Name-Drawer using Python and Tkinter

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.) Any feedback would be appreciated.

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 = ['Esther', 'Fatu', 'Osobie', 'Shannon', 'Ben', 'Kingsley','Eunhye', 'Jogi',
          'Sargis','Ethan', 'Stephane', 'Rachel', 'Naomi', 'Emma',
          'Dongmin','Stijn', 'Sydney','Jireh']
    self.draw_names(s7, self.count_s7)
        

def s8_Names(self):
    s8 = ['Dueng', 'Jacob', 'Hannah H.', 'Abbie', 'Sosha', 'Daniella', 'Mathias',
          'Hannah M.','Joanina', 'Vanessa',  'Ezra', 'Zoe', 'James', 'Ariela']
    self.draw_names(s8, self.count_s8)

def m10_Names(self):
    m10 = ['RoseAnna', 'Rahim', 'Dominic', 'Wendy', 'Beatrix', 'Junghee', 'Deborah',
           'Agasha', 'Landon']
    self.draw_names(m10, self.count_m10)
      
     

    

root=Tk()
root.title("Random Names")
app = App(root)
root.mainloop()
root.destroy()    

Simple name-drawer using Python and Tkinter

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 = ['Esther', 'Fatu', 'Osobie', 'Shannon', 'Ben', 'Kingsley','Eunhye', 'Jogi',
          'Sargis','Ethan', 'Stephane', 'Rachel', 'Naomi', 'Emma',
          'Dongmin','Stijn', 'Sydney','Jireh']
    self.draw_names(s7, self.count_s7)
        

def s8_Names(self):
    s8 = ['Dueng', 'Jacob', 'Hannah H.', 'Abbie', 'Sosha', 'Daniella', 'Mathias',
          'Hannah M.','Joanina', 'Vanessa',  'Ezra', 'Zoe', 'James', 'Ariela']
    self.draw_names(s8, self.count_s8)

def m10_Names(self):
    m10 = ['RoseAnna', 'Rahim', 'Dominic', 'Wendy', 'Beatrix', 'Junghee', 'Deborah',
           'Agasha', 'Landon']
    self.draw_names(m10, self.count_m10)
      
     

    

root=Tk()
root.title("Random Names")
app = App(root)
root.mainloop()
root.destroy()
Source Link
Loading