hi can't figure out what's wrong with my code. I'm trying to create a frame without a titlebar but still movable. When I run it, I can't drag the frame. hope you can help as soon as possible thanks a lot! cheers!

here's my code:

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, id):
        self.style = wx.SIMPLE_BORDER
        wx.Frame.__init__(self, parent, id, style = self.style)
        
        self.spacer1 = wx.StaticText(self, -1, '')
        self.spacer2 = wx.StaticText(self, -1, '')
        self.timetxt = wx.StaticText(self, -1,'00:00:00')       
        
        self.__set_properties()
        self.__do_layout()

        ## here is the bind thing!
        self.Bind(wx.EVT_MOTION, self.OnMouse)
   

    def __set_properties(self):
        ##Frame
        self.SetSize((250,80))

        ##Fonts        
        self.timetxt.SetFont(wx.Font(35, wx.MODERN, wx.NORMAL, wx.BOLD, 0, ""))
        self.spacer1.SetFont(wx.Font(10, wx.MODERN, wx.NORMAL, wx.BOLD, 0, ""))
        self.spacer2.SetFont(wx.Font(10, wx.MODERN, wx.NORMAL, wx.BOLD, 0, ""))
        

    def __do_layout(self):

        sizer1 = wx.BoxSizer(wx.VERTICAL)
        sizer1.Add(self.spacer1,0,wx.EXPAND, 0)
        sizer1.Add(self.timetxt,0,wx.ALIGN_CENTER_HORIZONTAL, 0)
        sizer1.Add(self.spacer2,0,wx.EXPAND, 0)

        self.SetSizer(sizer1)
        self.Layout()
        self.Centre()


    def OnMouse(self, evt): 
        if not evt.Dragging():
            self._dragPos = None
            return
        self.CaptureMouse()
        if not self._dragPos:
            self._dragPos = evt.GetPosition()
        else:
            pos = evt.GetPosition()
            displacement = self._dragPos - pos
            self.SetPosition(self.GetPosition() - displacement)
            



if __name__ == "__main__":
    app = wx.App()
    frame_1 = MyFrame(parent = None,id = -1)
    frame_1.Show()
    app.MainLoop()

Recommended Answers

All 2 Replies

I figured out something

I remove the wx.EXPAND at the spacer:

sizer1.Add(self.spacer1,0)
        sizer1.Add(self.timetxt,0,wx.ALIGN_CENTER_HORIZONTAL, 0)
        sizer1.Add(self.spacer2,0)

then I can drag the frame now except on the statictext that prints 00:00:00

any solution? thx!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.