¿Cómo puedo crear una aplicación sin bordes en Python (windows)?
-
28-10-2019 - |
Pregunta
Me gustaría saber cómo crear una aplicación en Windows que no tenga el borde predeterminado;en particular, la barra de título con botones de minimizar, maximizar y cerrar. Estoy pensando en escribir un programa de teletipo que ocupe un espacio estrecho en la parte superior o inferior de la pantalla, pero no lo intentaré a menos que sea posible hacer una aplicación delgada en Python.Se agradece cualquier ayuda con la terminología;tal vez no sé cómo hacer la pregunta correcta en una búsqueda.¿Tkinter tiene esta opción? Gracias
Solución
Encontré un ejemplo que respondió a mi pregunta aquí .overrideredirect(1)
es la función clave.
Me gusta este método porque estoy familiarizado con Tk y prefiero una solución Tk, pero vea las otras respuestas para encontrar soluciones alternativas.
import tkMessageBox
from Tkinter import *
class App():
def __init__(self):
self.root = Tk()
self.root.overrideredirect(1)
self.frame = Frame(self.root, width=320, height=200,
borderwidth=2, relief=RAISED)
self.frame.pack_propagate(False)
self.frame.pack()
self.bQuit = Button(self.frame, text="Quit",
command=self.root.quit)
self.bQuit.pack(pady=20)
self.bHello = Button(self.frame, text="Hello",
command=self.hello)
self.bHello.pack(pady=20)
def hello(self):
tkMessageBox.showinfo("Popup", "Hello!")
app = App()
app.root.mainloop()
Solo necesita agregar su propio botón de interrupción o método para salir.
Otros consejos
If you're willing to use Qt/PySide, take a look at QtCore.Qt.FramelessWindowHint
The code below just proves it's possible and doesn't try to be terribly useful. In particular, you will have to force kill the app to get the app to close. In a proper implementation, you would handle mouse events in a custom way to allow the user to move and close the application. To run this, you will need to install PySide.
Hacked up Code
import sys
from PySide import QtGui, QtCore
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow(parent=None, flags=QtCore.Qt.FramelessWindowHint)
MainFrame = QtGui.QFrame(MainWindow)
MainWindow.setCentralWidget(MainFrame)
MainFrameLayout = QtGui.QVBoxLayout(MainFrame)
label = QtGui.QLabel('A Label')
MainFrameLayout.addWidget(label)
MainWindow.show()
sys.exit(app.exec_())
Try Using QT Designer and Python (PyQT4)
and this code
from TestUI import Ui_MainWindow
class testQT4(QtGui.QMainWindow):
def __init__(self, parent=None):
super(testQT4, self).__init__(parent,Qt.CustomizeWindowHint)
self.ui = Ui_MainWindow()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = testQT4()
myapp.show()
sys.exit(app.exec_())
TestUI is your UI file Created by using "cmd" going into your project directory (by cd[space][your path here])
and typing this
pyuic4 resfile.ui -o TestUI.py
above will create the TestUI.py on projects folder
resfile.ui is the file that you made on QT Designer
Hope this helps.