Hi,

I'm a bit new to python and gui programming.
I was wondering if there was a way to display a widget on desktop such that when you minimize everything, my widget still displays?

I'm currently checking out PyGTK because I'm using gnome on linux, but if there's a cross-platform way say through wxWidgets, then I wouldn't mind switching over to wxWidgets,

TJ

You can use a dialog window in conjunction with a main window. Here is a wxPython example:

# a wxPython general frame with a dialog window
# the dialog shows full size even it the frame is minimized

import wx
import wx.calendar as cal

class MyCalendar(wx.Dialog):
    """create a simple dialog window with a calendar display"""
    def __init__(self, parent, mytitle):
        wx.Dialog.__init__(self, parent, wx.ID_ANY, mytitle)
        # use a box sizer to position controls vertically
        vbox = wx.BoxSizer(wx.VERTICAL)

        # wx.DateTime_Now() sets calendar to current date
        self.calendar = cal.CalendarCtrl(self, wx.ID_ANY, 
            wx.DateTime_Now())
        vbox.Add(self.calendar, 0, wx.EXPAND|wx.ALL, border=20)
        # click on day
        self.calendar.Bind(cal.EVT_CALENDAR_DAY, 
            self.onCalSelected)
        # change month
        self.calendar.Bind(cal.EVT_CALENDAR_MONTH, 
            self.onCalSelected)
        # change year
        self.calendar.Bind(cal.EVT_CALENDAR_YEAR, 
            self.onCalSelected)

        self.label = wx.StaticText(self, -1, 'click on a day')
        vbox.Add(self.label, 0, wx.EXPAND|wx.ALL, border=20)

        self.button = wx.Button(self, -1, 'Exit')
        vbox.Add(self.button, 0, wx.ALL|wx.ALIGN_CENTER, border=20)
        self.button.Bind(wx.EVT_BUTTON, self.onQuit)

        self.SetSizerAndFit(vbox)
        self.Show(True)
        self.Centre()

    def onCalSelected(self, event):
        #date = event.GetDate()
        date = self.calendar.GetDate()
        day = date.GetDay()
        # for some strange reason month starts with zero
        month = date.GetMonth() + 1
        # year is yyyy format
        year = date.GetYear()
        s1 = "%02d/%02d/%d \n" % (month, day, year)
        # or just take a slice of the first 8 characters
        # to show mm/dd/yy
        s2 = str(date)[0:8]
        self.label.SetLabel(s1 + s2)

    def onQuit(self, event):
        self.Destroy()


class MyFrame(wx.Frame):
    """create a frame as the main window"""
    def __init__(self, parent, mytitle, mysize):
        # use wx.ID_ANY or -1 as ID
        wx.Frame.__init__(self, parent, -1, mytitle, 
            pos=(10, 10), size=mysize)
        self.SetBackgroundColour("yellow")
        
        # this dialog will stay up even if MyFrame is minimzed
        mc = MyCalendar(None, 'dialog window with calendar')

        #
        # create widgets and action for the frame
        #

    def onAction(self, event):
        """ some action code"""
        pass


app = wx.App(0)
# create a MyFrame instance and show the frame
mytitle = 'main window'
width = 400
height = 300
MyFrame(None, mytitle, (width, height)).Show()
app.MainLoop()

Well, if you don't mind the looks, tkinter is the built-in graphical toolkit for python, so it is cross platform and the user would have to install anything besides python itself.

Regarding the code, this would cause the window (named main in this case) to be always on top:

main.wm_attributes("-topmost", 1)

If you need a full example with tk widgets let me know, I have plenty of them here.

Well, if you don't mind the looks, tkinter is the built-in graphical toolkit for python, so it is cross platform and the user would have to install anything besides python itself.

Regarding the code, this would cause the window (named main in this case) to be always on top:

main.wm_attributes("-topmost", 1)

If you need a full example with tk widgets let me know, I have plenty of them here.

An example would be nice, and much appreciated.

TJ

Here is your example:

from tkinter import *

def name():
    name = entry.get()
    text.delete(1.0, END)
    text.insert(END, "Hello " + name + "!")

main = Tk()
main.geometry("400x400")
main.resizable(0, 0)
main.wm_attributes("-topmost", 1)

label = Label(main, text="What's your name?")
entry = Entry(main)
button0 = Button(main, text="Say hello!", command=name)
button1 = Button(main, text="close", command=quit)
text = Text(main)

label.pack()
entry.pack()
button0.pack()
button1.pack()
text.pack()

main.mainloop()

Also, you can place the main.wm_attributes stuff inside a function and then create a binding to a keyboard shortcut, for example ctrl+t. Then the program would stay on top of the others after you press the shortcut. In this example, the window will always be on top.

Thank you for your example.

But it's not really doing what I expected, but I will play around with the wm_attributes.

Hmmm,maybe I did not understand properly... what is the behavior you are expecting? You want the windows to be "un-iconifiable" so that it can never be minimized?

I guess I want it to behave as though it was part of my wallpaper.

Because when I click on "show Desktop" it still minimizes the window ( in both examples ).

I guess I want it to behave as though it was part of my wallpaper.

Because when I click on "show Desktop" it still minimizes the window ( in both examples ).

That is not possible as cross-platform.

This question has already been answered. Start a new discussion instead.