How can I create a borderless application in Python (windows)?
Asked Answered
G

3

8

I would like to know how to create an application in Windows that does not have the default border; particularly the title bar with minimize, maximize, and close buttons. I'm thinking of writing a ticker program that takes up a narrow space at the top or bottom of the screen, but I won't attempt it unless it's possible to make a thin application in Python. Any help with terminology is appreciated; maybe I don't know how to ask the right question in searching. Does Tkinter have this option? Thanks

Godroon answered 21/2, 2012 at 3:18 Comment(1)
You could look into the WX moduleLuella
G
11

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

I like this method because I'm familiar with Tk and preferred a Tk solution, but see the other answers for alternate 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 need to add your own kill button or quit method.

Godroon answered 23/2, 2012 at 5:28 Comment(0)
O
8

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_())
Osanna answered 21/2, 2012 at 4:7 Comment(3)
Thanks for the reply. I've only used Tkinter in the past and just found an example that answers my question with Tk, but I'll read up on Qt and PySide and install it.Godroon
Feel free to take the answer that you put in your question, add it as an answer and then accept it as the answer since it best fits what you wanted.Osanna
Thanks for providing a concise and simple example - works like a charm.Vender
C
2

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.

Cateran answered 21/2, 2012 at 4:5 Comment(2)
Thanks for the reply. I've only used Tkinter so far. Is Qt recommended over Tk?Godroon
it depends on your needs. on my part QT and PyQT4 gives me all the flexibility i need in my program. and is easy on my level of programmingCateran

© 2022 - 2024 — McMap. All rights reserved.