How to create a borderless application in Python (windows)?

I would like to know how to create an application on Windows that does not have a default border; in particular, the title with the buttons "minimize", "maximize" and "close". I am thinking of writing a ticker program that occupies a narrow space at the top or bottom of the screen, but I will not try it if it is not possible to make a thin Python application. Any help with terminology is appreciated; maybe I don’t know how to ask the right question when searching. Does Tkinter have this parameter? Thanks

+6
source share
3 answers

I found an example that answered my question here . overrideredirect(1) is a key function.

I like this method because I am familiar with Tk and prefer the Tk solution, but see other answers for alternative solutions.

 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() 

Just add your own kill or quit button.

+7
source

If you want to use Qt / PySide , see QtCore.Qt.FramelessWindowHint . The code below just proves that it is possible. Try to be terribly useful. In particular, you will have to force kill the application in order to close the application. In the correct implementation, you will handle mouse events in a custom way so that the user can move and close the application. To run this, you will need to install PySide .

Hacked 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_()) 
+8
source

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 user interface file. Created using "cmd" in your project directory (cd [space] [your path here])

and typing this

 pyuic4 resfile.ui -o TestUI.py 

above will create the TestUI.py folder in the folder

resfile.ui is the file you created in QT Designer

Hope this helps.

+2
source

Source: https://habr.com/ru/post/908946/


All Articles