python_by_example/final/fin04.py

61 lines
2.2 KiB
Python
Raw Permalink Normal View History

2023-11-22 11:54:37 -03:00
import tkinter as tk
def fin_04():
"""Create a program that will display the following screen:
+-------------------------------------------------+
| ___________ ________________ |
| Enter a number: |___________| |View Times Table||
| ___________ |________________||
| | | ________________ |
| | | | Clear ||
| | | |________________||
| | | |
| | | |
| |___________| |
|_________________________________________________|
When the user enters a number in the first box and clicks on the "View
Times Table" button it should show the times table in the list area.
For instance, if the user entered 99 they would see the list as shown
in the example on the right. The "Clear" button should clear both boxes."""
com_bg = "dodger blue"
window = tk.Tk()
window.title("Tablas de Multiplicar")
window.geometry("400x300")
window["bg"] = com_bg
lbl_num = tk.Label(text="Ingresa un número:", font="Verdana 10")
lbl_num["bg"] = com_bg
lbl_num.place(x=20, y=20, width=130, height=30)
txt_in = tk.Entry()
txt_in.place(x=150, y=20, width=120, height=30)
def view():
num = txt_in.get()
clear()
if num.isdigit():
num = int(num)
for i in range(1,13):
lst_table.insert('end', f"{i} x {num} = {i*num}")
else:
clear()
def clear():
lst_table.delete(0, 'end')
txt_in.delete(0, 'end')
txt_in.focus()
btn_view = tk.Button(text="Ver tablas", width=100, height=30, command=view)
btn_view.place(x=280, y=20, width=100, height=30)
lst_table = tk.Listbox()
lst_table["justify"] = "left"
lst_table.place(x=150, y=60, width=120 ,height=230)
btn_clear = tk.Button(text="Limpiar", width=100, height=30, command=clear)
btn_clear.place(x=280, y=60, width=100, height=30)
txt_in.focus()
window.mainloop()