Практична робота з інформатики. Даю 40 балів.
Ответы
Ответ:
Перед запуском скрипту буде потрібно встановити дві бібліотеки(через cmd - якщо ви запускаєте у Windows):
- ManagerTk, командою: pip install ManagerTk
- PIL, командою: pip install Pillow
Python:
import tkinter
import ManagerTk
window = tkinter.Tk()
window.geometry("500x250")
window.resizable(False,False)
def redirect_1t2_page():
try:
h_value, p_value, n_value, k_value = (float(entry_h.get()), float(entry_p.get()), float(entry_n.get()), float(entry_k.get()))
if h_value < 0 or p_value < 0 or k_value < 0 or n_value < 0:
raise ValueError
height_water = h_value + p_value*n_value
hours_past = 0
water_level = h_value
while water_level < k_value:
hours_past += 1
water_level += p_value
result_res["text"] = f"Height water in lake past {n_value} hours: {height_water}cm."
result_res_3_page["text"] = f"Water level has been {k_value} cm past: {hours_past} hours."
error_title["text"] = ""
ManagerTk.redirect_pages(page_1, page_2)
except:
error_title["text"] = "Error! Please, enter correct values."
def redirect_2t1_page():
ManagerTk.redirect_pages(page_2, page_1)
def redirect_2t3_page():
ManagerTk.redirect_pages(page_2, page_3)
def redirect_3t1_page():
ManagerTk.redirect_pages(page_3, page_1)
def redirect_3t2_page():
ManagerTk.redirect_pages(page_3, page_2)
main_title = tkinter.Label(text="Water in the Lake", font="Console 20")
title_h, entry_h = tkinter.Label(text="Water level in the lake:"), tkinter.Entry()
title_p, entry_p = tkinter.Label(text="Level up water per hour:"), tkinter.Entry()
title_n, entry_n = tkinter.Label(text="Add hour(s):"), tkinter.Entry()
title_k, entry_k = tkinter.Label(text="Must be height water:"), tkinter.Entry()
button_start_res = tkinter.Button(text="Result", command=redirect_1t2_page)
image_lake = ManagerTk.add_url_image(window,"https://i.ibb.co/XjFxdrf/lake.png", (150,130))
image_lake_2 = ManagerTk.add_url_image(window,"https://i.ibb.co/LZLD5kL/lake-page-2.png", (150,130))
image_lake_3 = ManagerTk.add_url_image(window, "https://i.ibb.co/gtH0pFV/lake-page-3.png", (200,130))
error_title = tkinter.Label(text="", fg="red")
error_title.place({"x":20, "y": 230})
result_title = tkinter.Label(text="Result", font="Console 20")
result_res = tkinter.Label(text=">>")
result_res_3_page = tkinter.Label(text=">>")
button_2t1_page = tkinter.Button(text="Back", command=redirect_2t1_page)
button_3t1_page = tkinter.Button(text="Back to values", command=redirect_3t1_page)
button_2t3_page = tkinter.Button(text="Next result", command=redirect_2t3_page)
button_3t2_page = tkinter.Button(text="Preview result", command=redirect_3t2_page)
page_1 = [
[main_title, [140, 20]],
[title_h, [20, 100]], [entry_h, [200, 100]],
[title_k, [20, 120]], [entry_k, [200, 120]],
[title_n, [20, 140]], [entry_n, [200, 140]],
[title_p, [20, 160]], [entry_p, [200, 160]],
[image_lake, [350,70]],
[button_start_res, [20, 200]]
]
page_2 = [
[result_title, [200, 20]],
[result_res, [20, 100]],
[image_lake_2, [350,70]],
[button_2t1_page, [20, 215]],
[button_2t3_page, [180, 215]]
]
page_3 = [
[result_title, [200, 20]],
[result_res_3_page, [20, 100]],
[image_lake_3, [300,70]],
[button_3t2_page, [20, 215]],
[button_3t1_page, [180, 215]]
]
ManagerTk.create_mpage(window, page_1, "500x250")
window.mainloop()
Документації:
- ManagerTk | https://pypi.org/project/ManagerTk/0.1.post2/
- Tkinter | https://realpython.com/python-gui-tkinter/
Объяснение:
Сподіваюсь що допомогла.
Якщо буде потрібна допомога у наступних практичних з Tkinter чи тому подібне - можеш звертатися у Telegram(@DK50503), чи на цьому сайті.