Foro de elhacker.net

Programación => Scripting => Mensaje iniciado por: darkweb64 en 7 Octubre 2015, 18:54 pm



Título: [Python + tkinter] Ayuda con marco de una ventana y sus botones
Publicado por: darkweb64 en 7 Octubre 2015, 18:54 pm
Buen día miembros del foro, necesito ayuda para quitar por completo los botones de minimizar, maximizar y cerrar de una ventana estándar en tkinter.
He logrado quitar el botón de maximizar y minimizar como muestro en el código de abajo.
Pero quiero mantener el borde para que se vea el título de la ventana sin ningún botón.

Código:
from tkinter import *

root = Tk()
root.title("Ventana con nombre del programa")
#root.overrideredirect(1) # No me sirve quita todo
root.attributes("-toolwindow",-1) # Solo permite el botón cerra en una ventana
root.mainloop()



Título: Re: [Python + tkinter] Ayuda con marco de una ventana y sus botones
Publicado por: 0roch1 en 7 Octubre 2015, 19:11 pm
¿En qué sistema operativo estás trabajando?


Título: Re: [Python + tkinter] Ayuda con marco de una ventana y sus botones
Publicado por: darkweb64 en 7 Octubre 2015, 19:21 pm
Es para windows y uso python3.4


Título: Re: [Python + tkinter] Ayuda con marco de una ventana y sus botones
Publicado por: 0roch1 en 7 Octubre 2015, 20:00 pm
Nunca lo he intentado pero esto es algo que se me ocurre por el momento.

Código
  1. __author__ = '0roch1'
  2. # -*- coding: utf-8 -*-
  3. try:
  4.    from Tkinter import * # Python2
  5. except ImportError:
  6.  
  7.    from tkinter import * # Python3
  8.  
  9. def __Cancel(event=None): pass
  10.  
  11. root = Tk()
  12. root.title("Título")
  13. root.resizable(0,0)
  14. root.attributes("-toolwindow",-1)
  15. root.protocol('WM_DELETE_WINDOW', __Cancel )
  16.  
  17. root.mainloop()
  18.  

Otra cosa que se pude hacer es utilizar
Código
  1. root.overrideredirect(1)
  2.  

y después agregar un borde a la ventana.


Título: Re: [Python + tkinter] Ayuda con marco de una ventana y sus botones
Publicado por: darkweb64 en 7 Octubre 2015, 20:49 pm
Gracias, lo probé y aunque no quita el botón cerrar de la barra lo anula, aunque me parece extraño que exista una forma para quitar el de maximizar y minimizar y no ese.


Título: Re: [Python + tkinter] Ayuda con marco de una ventana y sus botones
Publicado por: 0roch1 en 7 Octubre 2015, 21:14 pm
No, no lo quita, decía que era posiblemente una forma, pensé que lo que te interesaba era que no cerraran la ventana pero más bien quieres quitarlo por diseño, no?.

Lo único que quieres quitar son los botones, dejar la barra de título y mantener el borde de la ventana?.


Título: Re: [Python + tkinter] Ayuda con marco de una ventana y sus botones
Publicado por: darkweb64 en 7 Octubre 2015, 21:51 pm
Sí, mantener la barra pero sin botones.


Título: Re: [Python + tkinter] Ayuda con marco de una ventana y sus botones
Publicado por: 0roch1 en 8 Octubre 2015, 20:58 pm
¿Qué intentas hacer?

Esto te servirá?.

Código
  1. """
  2. Python Tkinter Splash Screen
  3.  
  4. This script holds the class SplashScreen, which is simply a window without
  5. the top bar/borders of a normal window.
  6.  
  7. The window width/height can be a factor based on the total screen dimensions
  8. or it can be actual dimensions in pixels. (Just edit the useFactor property)
  9.  
  10. Very simple to set up, just create an instance of SplashScreen, and use it as
  11. the parent to other widgets inside it.
  12.  
  13. www.sunjay-varma.com
  14. """
  15.  
  16. from Tkinter import *
  17.  
  18. class SplashScreen(Frame):
  19.    def __init__(self, master=None, width=0.8, height=0.6, useFactor=True):
  20.        Frame.__init__(self, master)
  21.        self.pack(side=TOP, fill=BOTH, expand=YES)
  22.  
  23.        # get screen width and height
  24.        ws = self.master.winfo_screenwidth()
  25.        hs = self.master.winfo_screenheight()
  26.        w = (useFactor and ws*width) or width
  27.        h = (useFactor and ws*height) or height
  28.        # calculate position x, y
  29.        x = (ws/2) - (w/2)
  30.        y = (hs/2) - (h/2)
  31.        self.master.geometry('%dx%d+%d+%d' % (w, h, x, y))
  32.  
  33.        self.master.overrideredirect(True)
  34.        self.lift()
  35.  
  36. if __name__ == '__main__':
  37.    root = Tk()
  38.  
  39.    sp = SplashScreen(root)
  40.    sp.config(bg="#3366ff")
  41.  
  42.    m = Label(sp, text="This is a test of the splash screen\n\n\nThis is only a test.\nwww.sunjay-varma.com")
  43.    m.pack(side=TOP, expand=YES)
  44.    m.config(bg="#3366ff", justify=CENTER, font=("calibri", 29))
  45.  
  46.    Button(sp, text="Press this button to kill the program", bg='red', command=root.destroy).pack(side=BOTTOM, fill=X)
  47.    root.mainloop()
  48.  
Fuente: http://code.activestate.com/recipes/577271-tkinter-splash-screen/


No sé si es posible hacer exactamente lo que pides.