teslariu

place_tkinter

Mar 13th, 2021 (edited)
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.94 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # posicionamiento PLACE
  5.  
  6. import tkinter as tk  
  7. from tkinter import ttk
  8.  
  9. # creo una ventana y la abro
  10. ventana = tk.Tk()  
  11.  
  12. # pongo un titulo
  13. ventana.title("Posicionamiento PLACE")
  14.  
  15. # configuo el tamaño inicial
  16. ventana.configure(width=400, height=800)
  17.  
  18.  
  19. ###############   funciones  #######################
  20.  
  21. def sumar():
  22.     a = float(primer_sumando.get())
  23.     b = float(segundo_sumando.get())
  24.     print(f"{a} + {b} = {a+b}")
  25.     total.set(str(a+b))
  26.  
  27. def seleccion_listbox():
  28.     posicion_cursor = lista.curselection()
  29.     seleccion = lista.get(posicion_cursor)
  30.     print(seleccion)
  31.    
  32. def seleccion_combobox():
  33.     seleccion = combo.get()
  34.     print(seleccion)
  35.    
  36. def guardar():
  37.     estado = bool(estado_casilla.get())
  38.     if estado:
  39.         print("Ha aceptado las condiciones")
  40.     else:
  41.         print("Debe aceptar las condiciones")
  42.  
  43.  
  44. #####################################################
  45. total = tk.StringVar()
  46. total.set("0")
  47.  
  48.  
  49.  
  50. # botón con ancho y alto por defecto
  51. boton = ttk.Button(text="SUMAR", command=sumar)
  52. boton.place(x=50, y=10)
  53.  
  54. ############ campo del primer sumando ################
  55. primer_sumando = ttk.Entry()
  56. primer_sumando.place(x=50, y=60, width=100, height=25)
  57. etiqueta = ttk.Label(text="Ingrese el primer sumando")
  58. etiqueta.place(x=170, y=60)
  59.  
  60. ############ campo del segundo sumando ################
  61. segundo_sumando = ttk.Entry()
  62. segundo_sumando.place(x=50, y=110, width=100, height=25)
  63. etiqueta = ttk.Label(text="Ingrese el segundo sumando")
  64. etiqueta.place(x=170, y=110)
  65.  
  66. ############ campo de resultados ################
  67.  
  68. resultado = ttk.Entry(
  69.                 font = ('arial',12,'italic'),
  70.                 textvariable = total,
  71.                 state = tk.DISABLED,
  72.                 )
  73.                
  74.                
  75. resultado.place(x=50, y=160, width=100, height=25)
  76. etiqueta = ttk.Label(text="Total")
  77. etiqueta.place(x=170, y=160)
  78.  
  79.  
  80.  
  81. ############ otros widgets  #########################
  82.  
  83. ##### listbox
  84.  
  85. lista = tk.Listbox()
  86. lista.insert(0,"Python", "C", "C++", "Java")
  87. lista.place(x=10, y=200)
  88. boton = ttk.Button(text="Guardar selección", command=seleccion_listbox)
  89. boton.place(x=10, y=370)
  90.  
  91. #####  combobox
  92.  
  93. combo = ttk.Combobox(state="readonly",values=["Erlang","GO","Javascript"])
  94. combo.place(x=10, y=420)
  95. boton = ttk.Button(text="Guardar combobox", command=seleccion_combobox)
  96. boton.place(x=10, y=450)
  97.  
  98. ##### checkbutton
  99. estado_casilla = tk.BooleanVar()
  100. estado_casilla.set("True")
  101. casilla = ttk.Checkbutton(text="Acepto las condiciones", variable=estado_casilla)
  102. casilla.place(x=10, y=500)
  103. boton = ttk.Button(text="Guardar", command=guardar)
  104. boton.place(x=10, y=550)
  105.  
  106. ### imagenes (dentro de una etiqueta: bmp, png, gif):
  107. imagen = tk.PhotoImage(file="camion.png")
  108. label = ttk.Label(image=imagen)
  109. label.place(relx=0.5, rely=0.5, relwidth=0.5, relheight=0.5)
  110.  
  111.  
  112.  
  113. # mantengo la ventana abierta
  114. ventana.mainloop()
  115.  
Add Comment
Please, Sign In to add comment