0

I'm trying to create a windows app that shows weather like windows 10 widgets using Tkinter. The issue I ran into is that I cannot remove the window's border to make it look like a real widget.

Here's what it looks like and what I'd like to remove:
enter image description here

self.root.overrideredirect(1) kinda works but I still can minimize the window, which is what I do not want to be available.

That's what I want it to look and behave like:
enter image description here

To sum up:

  1. How to disable window title and all of that on top properly?
  2. How to move the window after, set the position of it on the screen?

I'm new to Python, any help is appreciated. Thank you all. Peace

To clarify: The app is supposed to be not affected by tab+alt (and other ways to minimize it) and be always on desktop, not on top of any other app, right on the desktop.

UPD

The thing I missed working around with win32gui is that I cannot get the handle the way I was trying to due to the fact that the code of getting the handle before the window itself was created (before mainloop) so root.wait_visibility() was the solution for me. After that I got the handle using EnumWindows and positioned my window the way I needed, finally disabling the border with root.overrideredirect. The suggested solutions will be tried as well. Thank you for help!

top-right corner of the desktop:
enter image description here

Reza Rahemtola
  • 1,182
  • 7
  • 16
  • 30
  • Does [this](https://stackoverflow.com/a/29643532/11106801) help for your second point? When you call `.overrideredirect(True)`, does it remove the title bar? – TheLizzard Jul 16 '21 at 13:28
  • This quite answers my question. Thank you. But again, it seems that .overrideredirect(True) does not make the app behave like what I mentioned in the post. The app is supposed to be not affected by tab+alt (and other ways to minimize it) and be always on desktop, not on top of any other app, right on the desktop. – Георгий Садовой Jul 16 '21 at 17:40
  • Try the `topmost` thing from [here](https://stackoverflow.com/a/6795115/11106801). That will force the window to always be on the top. – TheLizzard Jul 16 '21 at 17:45

1 Answers1

1

You can try this:

root.overrideredirect(1)
root.geometry('250x150+900+600')
#900+600 is x+y axis position of window

And for making close button like of widget you can make transparent frame in side, put button there and in command .destroy().

Edit
From TheLizzard's comment, visit here for further information. From there:

To make the window draggable, put bindings for (mouse clicks) and (mouse movements) on the window.

import tkinter

class Win(tkinter.Tk):

    def __init__(self,master=None):
        tkinter.Tk.__init__(self,master)
        self.overrideredirect(True)
        self._offsetx = 0
        self._offsety = 0
        self.bind('<Button-1>',self.clickwin)
        self.bind('<B1-Motion>',self.dragwin)

    def dragwin(self,event):
        x = self.winfo_pointerx() - self._offsetx
        y = self.winfo_pointery() - self._offsety
        self.geometry('+{x}+{y}'.format(x=x,y=y))

    def clickwin(self,event):
        self._offsetx = event.x
        self._offsety = event.y


win = Win()
win.mainloop()

You can use this for some part in top of the window rather then in whole window. By making new frame there implement it, to make your widget moveable.

And from second comment of TheLizzard, visit here for more information. From there:

If you want the window to stay above all other windows.

root.attributes("-topmost", True)
imxitiz
  • 3,920
  • 3
  • 9
  • 33
  • Just a quick question: why do you need the transparent canvas? – TheLizzard Jul 16 '21 at 13:43
  • Check windows widget, close button is in a like transparent part*. In a side as well* – imxitiz Jul 16 '21 at 13:46
  • I do actually think that the placement of the window could be done using win32gui library. But I'm not familiar with it enough to make it. Like, I've seen an idea with this library but I stumbled upon the issue that I cant get the pyhandle of the window properly, it must be active and mine is not. – Георгий Садовой Jul 16 '21 at 17:47
  • @ГеоргийСадовой You shouldn't use `win32gui` if you have `tkinter` methods that do the same thing. Don't know much about how `tcl` (the library that `tkinter` uses) functions internally but you might make the state of the window invalid in the eyes of `tcl`. That can use problems later on. – TheLizzard Jul 16 '21 at 17:53
  • @ГеоргийСадовой doesn't this answer or TheLizzard's comment solved your problem. What is your issue now? – imxitiz Jul 16 '21 at 17:56
  • @Kshitiz I think he/she want the window to always stay on the top. That is why I posted my last comment (on the question). – TheLizzard Jul 16 '21 at 17:58
  • @TheLizzard Yeah! I read that. I also agree with you. Can I copy answer from that your mentioned answer and edit my answer? That way my answer will be accepted or otherwise it should be close as duplicate! – imxitiz Jul 16 '21 at 17:58
  • @Kshitiz Feel free to copy both of my comments. When you update your answer, I will upvote it :D – TheLizzard Jul 16 '21 at 18:04
  • @TheLizzard check it, I had mentioned you in answer. It will be enough right? – imxitiz Jul 16 '21 at 18:19
  • I think so. Lets wait to see if it's what OP needs. – TheLizzard Jul 16 '21 at 18:22
  • Yeah! If I have further idea to solve OP's issue I will try to add them! – imxitiz Jul 16 '21 at 18:23
  • @ГеоргийСадовой you haven't checked the answer or what? You haven't responded anything! – imxitiz Jul 17 '21 at 01:51
  • @TheLizzard and the others (seems like i cant mention anyone else). Sincerely sorry guys, been seriously ill - that's the reason for my absence. I do want the window to be always on top, that's true. To be precise, always on top of the desktop but nowhere else and be borderless. I didn't really get the answer of TheLizzard about making the state of the window invalid in the eyes of tcl. How can I make it be the way you say? I appreciate your impact and effort, really. Sorry for the absence again/ – Георгий Садовой Jul 31 '21 at 00:08
  • Guys, I have pretty much achieved the things I wanted, still there're some questions remaining. I will update the post in a minute, to show all the changes. XD I've just only now have noticed the answer given by Xitiz, the one I'm commenting right now. I'm new to the stackoverflow and this is my first post here, so sorry again for being dumb. Thank you all, now I'll try to find how to close the discussion here. – Георгий Садовой Jul 31 '21 at 01:31
  • @ГеоргийСадовой what's the question. I don't think I understood your comment. – imxitiz Jul 31 '21 at 02:57
  • @Xitiz, yeah, you're right what I wrote was not really clear. I meant there are some questions besides, but I'll deal with them on my own. The question I asked in OP post is solved so thank you :) – Георгий Садовой Aug 04 '21 at 05:31