💄 Better display for main page button and display first image
This commit is contained in:
parent
cbb79b8cb7
commit
f820851db4
@ -1,2 +1,3 @@
|
|||||||
dearpygui
|
dearpygui
|
||||||
pathlib
|
pathlib
|
||||||
|
pillow
|
52
tk.py
52
tk.py
@ -2,6 +2,8 @@ from tkinter import *
|
|||||||
from tkinter import filedialog
|
from tkinter import filedialog
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
from PIL import ImageTk, Image
|
||||||
|
import random
|
||||||
|
|
||||||
root = Tk()
|
root = Tk()
|
||||||
root.title("Drawing Training!")
|
root.title("Drawing Training!")
|
||||||
@ -36,6 +38,17 @@ def format_seconds(seconds):
|
|||||||
return time
|
return time
|
||||||
|
|
||||||
|
|
||||||
|
def check_lets_draw():
|
||||||
|
global selected_folder
|
||||||
|
global found_images
|
||||||
|
global timer
|
||||||
|
|
||||||
|
if selected_folder != "" and len(found_images) > 0 and timer != 0:
|
||||||
|
launch_button.config(state="normal")
|
||||||
|
else:
|
||||||
|
launch_button.config(state="disabled")
|
||||||
|
|
||||||
|
|
||||||
def set_timer_in_seconds(user_data):
|
def set_timer_in_seconds(user_data):
|
||||||
global timer
|
global timer
|
||||||
timer = user_data
|
timer = user_data
|
||||||
@ -44,7 +57,30 @@ def set_timer_in_seconds(user_data):
|
|||||||
if button['text'] == format_seconds(timer):
|
if button['text'] == format_seconds(timer):
|
||||||
button.config(bg="blue")
|
button.config(bg="blue")
|
||||||
else:
|
else:
|
||||||
button.config(bg="grey")
|
button.config(bg="SystemButtonFace")
|
||||||
|
check_lets_draw()
|
||||||
|
|
||||||
|
|
||||||
|
def lets_draw():
|
||||||
|
global found_images
|
||||||
|
image_window = Toplevel(root)
|
||||||
|
image_window.title("Image")
|
||||||
|
image_window.geometry("200x200")
|
||||||
|
random.shuffle(found_images)
|
||||||
|
image = found_images[0]
|
||||||
|
found_images.pop(0)
|
||||||
|
display_new_image(image_window, image)
|
||||||
|
|
||||||
|
|
||||||
|
def display_new_image(image_window, image):
|
||||||
|
image1 = Image.open(image)
|
||||||
|
test = ImageTk.PhotoImage(image1)
|
||||||
|
|
||||||
|
label1 = Label(image_window, image=test)
|
||||||
|
label1.image = test
|
||||||
|
|
||||||
|
# Position image
|
||||||
|
label1.place(x=0, y=0)
|
||||||
|
|
||||||
|
|
||||||
def select_folder():
|
def select_folder():
|
||||||
@ -56,6 +92,7 @@ def select_folder():
|
|||||||
found_images = list(p.resolve() for p in Path(selected_folder).glob("**/*") if p.suffix in {".jpg", ".gif", ".png"})
|
found_images = list(p.resolve() for p in Path(selected_folder).glob("**/*") if p.suffix in {".jpg", ".gif", ".png"})
|
||||||
folder_name.config(text="Folder : " + selected_folder)
|
folder_name.config(text="Folder : " + selected_folder)
|
||||||
images_len.config(text="Found : " + str(len(found_images)))
|
images_len.config(text="Found : " + str(len(found_images)))
|
||||||
|
check_lets_draw()
|
||||||
|
|
||||||
|
|
||||||
title = Label(root, text="Drawing Training")
|
title = Label(root, text="Drawing Training")
|
||||||
@ -70,15 +107,22 @@ folder_name.pack()
|
|||||||
images_len = Label(root, text="Found : " + str(len(found_images)))
|
images_len = Label(root, text="Found : " + str(len(found_images)))
|
||||||
images_len.pack()
|
images_len.pack()
|
||||||
|
|
||||||
|
button_frame = Frame(root)
|
||||||
|
button_frame.pack(fill=X)
|
||||||
|
|
||||||
timers = [30, 45, 60, 120, 300, 600]
|
timers = [30, 45, 60, 120, 300, 600]
|
||||||
buttons = []
|
buttons = []
|
||||||
|
i = 0
|
||||||
for i in timers:
|
for i in timers:
|
||||||
t = i
|
t = i
|
||||||
new_button = Button(root, text=format_seconds(t), command=partial(set_timer_in_seconds, t))
|
new_button = Button(button_frame, text=format_seconds(t), command=partial(set_timer_in_seconds, t))
|
||||||
new_button.pack(side="left")
|
# new_button.pack(side="left")
|
||||||
buttons.append(new_button)
|
buttons.append(new_button)
|
||||||
|
button_frame.columnconfigure(i, weight=1)
|
||||||
|
new_button.grid(row=0, column=i, sticky=W + E)
|
||||||
|
i += 1
|
||||||
|
|
||||||
launch_button = Button(root, text="Let's draw!")
|
launch_button = Button(root, text="Let's draw!", command=lets_draw, state="disabled")
|
||||||
launch_button.pack(side="bottom")
|
launch_button.pack(side="bottom")
|
||||||
|
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
Loading…
Reference in New Issue
Block a user