from tkinter import * import random class Foo: def __init__(self, parent): # Make a frame with a label and underneath a button self.color_frame = Frame(parent, width=600, height=200, bg=background_color, padx=padding_x, pady=padding_y) self.color_frame.grid() # put in text label (row 0, column 0) # put in button (row 1, column 0) def change_color(self): # fg=color_code2 print("hello") def rand_color(self): hex_chars = ['a', 'b', 'c', 'd', 'e', 'f', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'] color_code = "#" for i in range(6): color_code += hex_chars[randrange(len(hex_chars))] return color_code # main routine if __name__ == "__main__": root = Tk() root.title("title goes here") something = Foo(root) root.mainloop()