Jan-07-2019, 12:54 PM
Hi Dwimmerlaik
Here one of many solutions:
Here one of many solutions:
import random import tkinter as tk from tkinter.colorchooser import * APP_TITLE = "Choose Color" APP_XPOS = 100 APP_YPOS = 100 APP_WIDTH = 350 APP_HEIGHT = 200 class Application(object): def __init__(self, main_win): self.main_win = main_win self.build() def build(self): main_frame = tk.Frame(self.main_win) main_frame.pack(fill='both', expand=True) tk.Button(main_frame, text = 'Choose color', command=self.getColor ).pack(pady=4) self.canvas = tk.Canvas(main_frame, width=400, height=400) self.canvas.pack() def random_sqaure(self, width, height, fill_color): x1 = random.randrange(width) y1 = random.randrange(height) x2 = random.randrange(x1 + random.randrange(width)) y2 = random.randrange(y1 + random.randrange(height)) canvas.create_rectangle(x1, y1, x2, y2, fill=fill_color) def getColor(self): color = askcolor()[1] print(color) self.canvas['bg'] = color def main(): main_win = tk.Tk() main_win.title(APP_TITLE) #main_win.geometry("+{}+{}".format(APP_XPOS, APP_YPOS)) #main_win.geometry("{}x{}".format(APP_WIDTH, APP_HEIGHT)) app = Application(main_win) main_win.mainloop() if __name__ == '__main__': main()wuf