|
1 |
| -import os |
2 |
| -import ttkbootstrap as ttk |
3 |
| -from ttkbootstrap.constants import * |
4 |
| - |
5 |
| -class GetContact(): |
6 |
| - """Request contact information on screen |
7 |
| - |
8 |
| - Attributes: |
9 |
| - Name (str): The contact's name |
10 |
| - Address (str): The contact's address |
11 |
| - Phone (str): The contact's phone number |
12 |
| - |
13 |
| - Examples: |
14 |
| - >>> Contact = GetContact() |
15 |
| - >>> print( f"Name: {Contact.Name}" ) |
16 |
| - >>> print( f"Address: {Contact.Address}" ) |
17 |
| - >>> print( f"Phone: {Contact.Phone}" ) |
18 |
| - Name: Fin392 |
19 |
| - |
20 |
| - Phone: 555-555-555 |
21 |
| - """ |
22 |
| - |
23 |
| - def __init__( self ): |
24 |
| - # Font to be used |
25 |
| - CUSTOM_FONT = ( "Comic Sans MS", 12, "normal" ) |
26 |
| - |
27 |
| - # Get script path |
28 |
| - strScriptPath = os.path.dirname(os.path.realpath(__file__)) |
29 |
| - |
30 |
| - # Create window and a frame |
31 |
| - self.ttkWindow = ttk.Window( themename = "darkly" ) |
32 |
| - self.ttkWindow.overrideredirect( True ) |
33 |
| - self.ttkWindow.geometry( "+200+100" ) |
34 |
| - self.ttkWindow.resizable( False, False ) |
35 |
| - self.ttkWindow.title( "myPYApplication (powered by ttkbootstrap)" ) |
36 |
| - self.ttkWindow.iconbitmap( strScriptPath+"\\..\\Assets\\myPYApplication.ico" ) |
37 |
| - ttkFrame = ttk.Frame( self.ttkWindow, padding=10 ) |
38 |
| - ttkFrame.pack( fill=ttk.BOTH, expand=ttk.YES ) |
39 |
| - |
40 |
| - # Variables |
41 |
| - self.Name = ttk.StringVar(value="") |
42 |
| - self.Address = ttk.StringVar(value="") |
43 |
| - self.Phone = ttk.StringVar(value="") |
44 |
| - |
45 |
| - # Cabecera del formulario |
46 |
| - ttkLblHearder = ttk.Label( ttkFrame, text = "Please enter your contact information", font=CUSTOM_FONT, bootstyle=DEFAULT ) |
47 |
| - |
48 |
| - # Etiquetas |
49 |
| - ttkLblName = ttk.Label( ttkFrame, text = "Name", font=CUSTOM_FONT, bootstyle=DEFAULT ) |
50 |
| - ttkLblAddress = ttk.Label( ttkFrame, text = "Address", font=CUSTOM_FONT, bootstyle=DEFAULT ) |
51 |
| - ttkLblPhone = ttk.Label( ttkFrame, text = "Phone", font=CUSTOM_FONT, bootstyle=DEFAULT ) |
52 |
| - |
53 |
| - # Entradas |
54 |
| - ttkEntName = ttk.Entry( ttkFrame, textvariable=self.Name , font=CUSTOM_FONT, bootstyle=DEFAULT ) |
55 |
| - ttkEntAddress = ttk.Entry( ttkFrame, textvariable=self.Address, font=CUSTOM_FONT, bootstyle=DEFAULT ) |
56 |
| - ttkEntPhone = ttk.Entry( ttkFrame, textvariable=self.Phone , font=CUSTOM_FONT, bootstyle=DEFAULT ) |
57 |
| - |
58 |
| - # Botones |
59 |
| - ttkBtnCancelar = ttk.Button( ttkFrame, text="Cancelar", bootstyle=DANGER, command=self.on_cancelar ) |
60 |
| - ttkBtnEnviar = ttk.Button( ttkFrame, text="Enviar", bootstyle=SUCCESS, command=self.on_enviar ) |
61 |
| - |
62 |
| - # Coloca los elementos |
63 |
| - ttkLblHearder.grid( row=1, column=1, columnspan=3, padx=10, pady=10, sticky="nswe" ) |
64 |
| - ttkLblName.grid( row=2, column=1, columnspan=1, padx=10, pady=10, sticky="nswe" ) |
65 |
| - ttkLblAddress.grid( row=3, column=1, columnspan=1, padx=10, pady=10, sticky="nswe" ) |
66 |
| - ttkLblPhone.grid( row=4, column=1, columnspan=1, padx=10, pady=10, sticky="nswe" ) |
67 |
| - ttkEntName.grid( row=2, column=2, columnspan=2, padx=10, pady=10, sticky="nswe" ) |
68 |
| - ttkEntAddress.grid( row=3, column=2, columnspan=2, padx=10, pady=10, sticky="nswe" ) |
69 |
| - ttkEntPhone.grid( row=4, column=2, columnspan=2, padx=10, pady=10, sticky="nswe" ) |
70 |
| - ttkBtnCancelar.grid( row=5, column=2, columnspan=1, padx=10, pady=10, sticky="nswe" ) |
71 |
| - ttkBtnEnviar.grid( row=5, column=3, columnspan=1, padx=10, pady=10, sticky="nswe" ) |
72 |
| - |
73 |
| - # Inicia la ventana |
74 |
| - self.ttkWindow.mainloop() |
75 |
| - |
76 |
| - def on_cancelar(self ): |
77 |
| - self.Name = None |
78 |
| - self.Address = None |
79 |
| - self.Phone = None |
80 |
| - self.ttkWindow.quit() |
81 |
| - |
82 |
| - def on_enviar(self): |
83 |
| - self.Name = self.Name.get() |
84 |
| - self.Address = self.Address.get() |
85 |
| - self.Phone = self.Phone.get() |
86 |
| - self.ttkWindow.quit() |
87 |
| - |
88 |
| -def main(): |
89 |
| - Contact = GetContact() |
90 |
| - |
91 |
| - if Contact.Name is not None: |
92 |
| - print( f"Name : {Contact.Name}" ) |
93 |
| - print( f"Address: {Contact.Address}" ) |
94 |
| - print( f"Phone : {Contact.Phone}" ) |
95 |
| - else: |
96 |
| - print( "No values returned" ) |
97 |
| - |
98 |
| -if __name__ == "__main__": |
99 |
| - main() |
| 1 | +import os |
| 2 | +import ttkbootstrap as ttk |
| 3 | +from ttkbootstrap.constants import * |
| 4 | + |
| 5 | +class GetContact(): |
| 6 | + """Request contact information on screen |
| 7 | + |
| 8 | + Attributes: |
| 9 | + Name (str): The contact's name |
| 10 | + Address (str): The contact's address |
| 11 | + Phone (str): The contact's phone number |
| 12 | + |
| 13 | + Examples: |
| 14 | + >>> Contact = GetContact() |
| 15 | + >>> print( f"Name: {Contact.Name}" ) |
| 16 | + >>> print( f"Address: {Contact.Address}" ) |
| 17 | + >>> print( f"Phone: {Contact.Phone}" ) |
| 18 | + Name: Fin392 |
| 19 | + |
| 20 | + Phone: 555-555-555 |
| 21 | + """ |
| 22 | + |
| 23 | + def __init__( self ): |
| 24 | + # Font to be used |
| 25 | + CUSTOM_FONT = ( "Comic Sans MS", 12, "normal" ) |
| 26 | + |
| 27 | + # Get script path |
| 28 | + strScriptPath = os.path.dirname(os.path.realpath(__file__)) |
| 29 | + |
| 30 | + # Create window and a frame |
| 31 | + self.ttkWindow = ttk.Window( themename = "darkly" ) |
| 32 | + self.ttkWindow.overrideredirect( True ) |
| 33 | + self.ttkWindow.geometry( "+200+100" ) |
| 34 | + self.ttkWindow.resizable( False, False ) |
| 35 | + self.ttkWindow.title( "myPYApplication (powered by ttkbootstrap)" ) |
| 36 | + self.ttkWindow.iconbitmap( strScriptPath+"\\..\\Assets\\myPYApplication.ico" ) |
| 37 | + ttkFrame = ttk.Frame( self.ttkWindow, padding=10 ) |
| 38 | + ttkFrame.pack( fill=ttk.BOTH, expand=ttk.YES ) |
| 39 | + |
| 40 | + # Variables |
| 41 | + self.Name = ttk.StringVar(value="") |
| 42 | + self.Address = ttk.StringVar(value="") |
| 43 | + self.Phone = ttk.StringVar(value="") |
| 44 | + |
| 45 | + # Cabecera del formulario |
| 46 | + ttkLblHearder = ttk.Label( ttkFrame, text = "Please enter your contact information", font=CUSTOM_FONT, bootstyle=DEFAULT ) |
| 47 | + |
| 48 | + # Etiquetas |
| 49 | + ttkLblName = ttk.Label( ttkFrame, text = "Name", font=CUSTOM_FONT, bootstyle=DEFAULT ) |
| 50 | + ttkLblAddress = ttk.Label( ttkFrame, text = "Address", font=CUSTOM_FONT, bootstyle=DEFAULT ) |
| 51 | + ttkLblPhone = ttk.Label( ttkFrame, text = "Phone", font=CUSTOM_FONT, bootstyle=DEFAULT ) |
| 52 | + |
| 53 | + # Entradas |
| 54 | + ttkEntName = ttk.Entry( ttkFrame, textvariable=self.Name , font=CUSTOM_FONT, bootstyle=DEFAULT ) |
| 55 | + ttkEntAddress = ttk.Entry( ttkFrame, textvariable=self.Address, font=CUSTOM_FONT, bootstyle=DEFAULT ) |
| 56 | + ttkEntPhone = ttk.Entry( ttkFrame, textvariable=self.Phone , font=CUSTOM_FONT, bootstyle=DEFAULT ) |
| 57 | + |
| 58 | + # Botones |
| 59 | + ttkBtnCancelar = ttk.Button( ttkFrame, text="Cancelar", bootstyle=DANGER, command=self.on_cancelar ) |
| 60 | + ttkBtnEnviar = ttk.Button( ttkFrame, text="Enviar", bootstyle=SUCCESS, command=self.on_enviar ) |
| 61 | + |
| 62 | + # Coloca los elementos |
| 63 | + ttkLblHearder.grid( row=1, column=1, columnspan=3, padx=10, pady=10, sticky="nswe" ) |
| 64 | + ttkLblName.grid( row=2, column=1, columnspan=1, padx=10, pady=10, sticky="nswe" ) |
| 65 | + ttkLblAddress.grid( row=3, column=1, columnspan=1, padx=10, pady=10, sticky="nswe" ) |
| 66 | + ttkLblPhone.grid( row=4, column=1, columnspan=1, padx=10, pady=10, sticky="nswe" ) |
| 67 | + ttkEntName.grid( row=2, column=2, columnspan=2, padx=10, pady=10, sticky="nswe" ) |
| 68 | + ttkEntAddress.grid( row=3, column=2, columnspan=2, padx=10, pady=10, sticky="nswe" ) |
| 69 | + ttkEntPhone.grid( row=4, column=2, columnspan=2, padx=10, pady=10, sticky="nswe" ) |
| 70 | + ttkBtnCancelar.grid( row=5, column=2, columnspan=1, padx=10, pady=10, sticky="nswe" ) |
| 71 | + ttkBtnEnviar.grid( row=5, column=3, columnspan=1, padx=10, pady=10, sticky="nswe" ) |
| 72 | + |
| 73 | + # Inicia la ventana |
| 74 | + self.ttkWindow.mainloop() |
| 75 | + |
| 76 | + def on_cancelar(self ): |
| 77 | + self.Name = None |
| 78 | + self.Address = None |
| 79 | + self.Phone = None |
| 80 | + self.ttkWindow.quit() |
| 81 | + |
| 82 | + def on_enviar(self): |
| 83 | + self.Name = self.Name.get() |
| 84 | + self.Address = self.Address.get() |
| 85 | + self.Phone = self.Phone.get() |
| 86 | + self.ttkWindow.quit() |
| 87 | + |
| 88 | +def main(): |
| 89 | + Contact = GetContact() |
| 90 | + |
| 91 | + if Contact.Name is not None: |
| 92 | + print( f"Name : {Contact.Name}" ) |
| 93 | + print( f"Address: {Contact.Address}" ) |
| 94 | + print( f"Phone : {Contact.Phone}" ) |
| 95 | + else: |
| 96 | + print( "No values returned" ) |
| 97 | + |
| 98 | +if __name__ == "__main__": |
| 99 | + main() |
0 commit comments