54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
|
from os import getcwd as pwd
|
||
|
import tkinter as tk
|
||
|
|
||
|
def tk_10():
|
||
|
"""Create your own icon that consists of several vertical multi-coloured
|
||
|
lines. Create a logo which measures 200 x 150, using Paint or another
|
||
|
graphics package. Create the following window using your own icon and
|
||
|
logo.When the user enters their name and clicks on the Press Me button
|
||
|
it should display "Hello" and their name in the second text box."""
|
||
|
base_path = f"{pwd()}/tkgui/imgs"
|
||
|
c_bg="magenta"
|
||
|
window = tk.Tk()
|
||
|
window.geometry("400x300")
|
||
|
window.configure(background=c_bg)
|
||
|
|
||
|
title_icon = tk.PhotoImage(file = f"{base_path}/devfzn_64x64.png")
|
||
|
window.iconphoto(False, title_icon)
|
||
|
window.title("Saludo Tk")
|
||
|
|
||
|
photo1 = tk.PhotoImage(file = f"{base_path}/img_4.png")
|
||
|
photobox1 = tk.Label(window, image=photo1)
|
||
|
photobox1["image"] = photo1
|
||
|
photobox1["bg"] = c_bg
|
||
|
photobox1.place(x=70,y=0,width=250,height=200)
|
||
|
|
||
|
name_in = tk.Entry()
|
||
|
name_in.place(x=120, y=200, width=160, height=30)
|
||
|
|
||
|
lbl_name = tk.Message(text="Nombre", font="Verdana 12")
|
||
|
lbl_name["bg"] = c_bg
|
||
|
lbl_name["width"] = 70
|
||
|
lbl_name["justify"] = "center"
|
||
|
lbl_name.place(x=40, y=200, width=70, height=30)
|
||
|
|
||
|
lbl_msg = tk.Message(text="", font="Verdana 18")
|
||
|
lbl_msg.place(x=160, y=240, width=200, height=30)
|
||
|
lbl_msg["justify"] = "left"
|
||
|
lbl_msg["width"] = 200
|
||
|
lbl_msg["bg"] = c_bg
|
||
|
|
||
|
def clicked():
|
||
|
sel = name_in.get()
|
||
|
name_in["text"] = ""
|
||
|
msg = f"Hola {sel}"
|
||
|
lbl_msg["text"] = msg
|
||
|
name_in.focus()
|
||
|
|
||
|
button = tk.Button(text="Click", command=clicked)
|
||
|
button.place(x=40, y=240, width=100, height=30)
|
||
|
name_in.focus()
|
||
|
|
||
|
|
||
|
window.mainloop()
|