Button overlaying text

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Button overlaying text

dncarac
As part of a game I"m working on, I want a dialog with a static text control, with a relatively small button which is placed at random locations atop the text.  I can do this in TKinter and QT, but they have problems with unittesting.  I tried this with wxPython, but it doesn't work.  I'm assuming I did something wrong since it is so easy to do in the other frameworks.  Here is the code I've tried:
import wx
wxApp
= wx.App()
dlg
= wx.Dialog(None)
btn
= wx.Button(dlg, label="Button")
txt
= wx.StaticText(dlg, label="Static text", size=dlg.GetClientSize())
dlg
.Show()
wxApp
.MainLoop()
What it does is display a dialog with text, but the button doesn't appear until the mouse is moved over the button, then the button appears. I've tried wx.Raise() the button, and wx.Lower() the text and both - no change.  I"ve tried changing the order of the txt and btn lines.  I've tried wx.Frame instead of wx.Dialog - no change.  I tried a Frame with an included Panel - didn't work.

Any help is appreciated.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Button overlaying text

张慧聪
Maybe you should try to set the pos parameter.
I recommend to use wx.BoxSizer to align your elements

On Mon, Jan 14, 2019 at 5:55 AM dncarac <[hidden email]> wrote:
As part of a game I"m working on, I want a dialog with a static text control, with a relatively small button which is placed at random locations atop the text.  I can do this in TKinter and QT, but they have problems with unittesting.  I tried this with wxPython, but it doesn't work.  I'm assuming I did something wrong since it is so easy to do in the other frameworks.  Here is the code I've tried:
import wx
wxApp
= wx.App()
dlg
= wx.Dialog(None)
btn
= wx.Button(dlg, label="Button")
txt
= wx.StaticText(dlg, label="Static text", size=dlg.GetClientSize())
dlg
.Show()
wxApp
.MainLoop()
What it does is display a dialog with text, but the button doesn't appear until the mouse is moved over the button, then the button appears. I've tried wx.Raise() the button, and wx.Lower() the text and both - no change.  I"ve tried changing the order of the txt and btn lines.  I've tried wx.Frame instead of wx.Dialog - no change.  I tried a Frame with an included Panel - didn't work.

Any help is appreciated.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.


--

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Button overlaying text

john fabiani`
Add a couple of panels to dialog along with some sizers.  See the many tutorials on line.  As far as the random placement of the button above the text - I see nothing you are doing to randomize the location of the button.  It's been my experience mixing sizers and positional control does not work very well.  I'll guess that finding the button is part of the game.  Therefore, I would create a thread to handle moving the button.

Johnf

On 01/13/2019 07:45 PM, 张慧聪 wrote:
Maybe you should try to set the pos parameter.
I recommend to use wx.BoxSizer to align your elements

On Mon, Jan 14, 2019 at 5:55 AM dncarac <[hidden email]> wrote:
As part of a game I"m working on, I want a dialog with a static text control, with a relatively small button which is placed at random locations atop the text.  I can do this in TKinter and QT, but they have problems with unittesting.  I tried this with wxPython, but it doesn't work.  I'm assuming I did something wrong since it is so easy to do in the other frameworks.  Here is the code I've tried:
import wx
wxApp
= wx.App()
dlg
= wx.Dialog(None)
btn
= wx.Button(dlg, label="Button")
txt
= wx.StaticText(dlg, label="Static text", size=dlg.GetClientSize())
dlg
.Show()
wxApp
.MainLoop()
What it does is display a dialog with text, but the button doesn't appear until the mouse is moved over the button, then the button appears. I've tried wx.Raise() the button, and wx.Lower() the text and both - no change.  I"ve tried changing the order of the txt and btn lines.  I've tried wx.Frame instead of wx.Dialog - no change.  I tried a Frame with an included Panel - didn't work.

Any help is appreciated.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.


--
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Button overlaying text

Robin Dunn
In reply to this post by dncarac
On Sunday, January 13, 2019 at 1:55:48 PM UTC-8, dncarac wrote:
As part of a game I"m working on, I want a dialog with a static text control, with a relatively small button which is placed at random locations atop the text.  I can do this in TKinter and QT, but they have problems with unittesting.  I tried this with wxPython, but it doesn't work.  I'm assuming I did something wrong since it is so easy to do in the other frameworks.  Here is the code I've tried:
import wx
wxApp
= wx.App()
dlg
= wx.Dialog(None)
btn
= wx.Button(dlg, label="Button")
txt
= wx.StaticText(dlg, label="Static text", size=dlg.GetClientSize())
dlg
.Show()
wxApp
.MainLoop()
What it does is display a dialog with text, but the button doesn't appear until the mouse is moved over the button, then the button appears. I've tried wx.Raise() the button, and wx.Lower() the text and both - no change.  I"ve tried changing the order of the txt and btn lines.  I've tried wx.Frame instead of wx.Dialog - no change.  I tried a Frame with an included Panel - didn't work.


The behavior of overlapping sibling widgets (have the same parent and occupy the same area) is undefined in wxWidgets. If you want the button to hide the text when it is active then call the static text's Hide() method. If what you really want is for them to appear next to each other then you either need to specify positions or use a sizer as others have mentioned. There is no automatic stacking or packing like in some toolkits.
 
--
Robin

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Button overlaying text

Robin Dunn
On Monday, January 14, 2019 at 8:46:59 AM UTC-8, Robin Dunn wrote:
On Sunday, January 13, 2019 at 1:55:48 PM UTC-8, dncarac wrote:
As part of a game I"m working on, I want a dialog with a static text control, with a relatively small button which is placed at random locations atop the text.  I can do this in TKinter and QT, but they have problems with unittesting.  I tried this with wxPython, but it doesn't work.  I'm assuming I did something wrong since it is so easy to do in the other frameworks.  Here is the code I've tried:
import wx
wxApp
= wx.App()
dlg
= wx.Dialog(None)
btn
= wx.Button(dlg, label="Button")
txt
= wx.StaticText(dlg, label="Static text", size=dlg.GetClientSize())
dlg
.Show()
wxApp
.MainLoop()
What it does is display a dialog with text, but the button doesn't appear until the mouse is moved over the button, then the button appears. I've tried wx.Raise() the button, and wx.Lower() the text and both - no change.  I"ve tried changing the order of the txt and btn lines.  I've tried wx.Frame instead of wx.Dialog - no change.  I tried a Frame with an included Panel - didn't work.


The behavior of overlapping sibling widgets (have the same parent and occupy the same area) is undefined in wxWidgets. If you want the button to hide the text when it is active then call the static text's Hide() method. If what you really want is for them to appear next to each other then you either need to specify positions or use a sizer as others have mentioned. There is no automatic stacking or packing like in some toolkits.

Also, if you do need to keep the text (partially) visible with the button on top of it, then try making the text be the parent widget of the button. This will probably work on Windows, not sure about the others since static text is not intended to be a container widget. Another option would be to draw the text yourself in the panel's EVT_PAINT handler and keep the button as a child of the panel. Then you won't have the overlapping siblings problem.

--
Robin

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Button overlaying text

dncarac
In reply to this post by john fabiani`
Randomizing the position of the button is trivial, so I left it out.  If I can't get a button a text to coexist the way I want at fixed positions, I'm still stuck.  I didn't use sizers because they purposely do not overlay widgets.

On Monday, January 14, 2019 at 7:52:55 AM UTC-8, johnf wrote:
Add a couple of panels to dialog along with some sizers.  See the many tutorials on line.  As far as the random placement of the button above the text - I see nothing you are doing to randomize the location of the button.  It's been my experience mixing sizers and positional control does not work very well.  I'll guess that finding the button is part of the game.  Therefore, I would create a thread to handle moving the button.

Johnf

On 01/13/2019 07:45 PM, 张慧聪 wrote:
Maybe you should try to set the pos parameter.
I recommend to use wx.BoxSizer to align your elements

On Mon, Jan 14, 2019 at 5:55 AM dncarac <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="QQdRYKmcEgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">paten...@...> wrote:
As part of a game I"m working on, I want a dialog with a static text control, with a relatively small button which is placed at random locations atop the text.  I can do this in TKinter and QT, but they have problems with unittesting.  I tried this with wxPython, but it doesn't work.  I'm assuming I did something wrong since it is so easy to do in the other frameworks.  Here is the code I've tried:
import wx
wxApp
= wx.App()
dlg
= wx.Dialog(None)
btn
= wx.Button(dlg, label="Button")
txt
= wx.StaticText(dlg, label="Static text", size=dlg.GetClientSize())
dlg
.Show()
wxApp
.MainLoop()
What it does is display a dialog with text, but the button doesn't appear until the mouse is moved over the button, then the button appears. I've tried wx.Raise() the button, and wx.Lower() the text and both - no change.  I"ve tried changing the order of the txt and btn lines.  I've tried wx.Frame instead of wx.Dialog - no change.  I tried a Frame with an included Panel - didn't work.

Any help is appreciated.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="QQdRYKmcEgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">wxpython-user...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.


--
<a href="http://blog.bukn.info" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fblog.bukn.info\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGZRP1cojlBHBce9xrylhR-rbv3Wg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fblog.bukn.info\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGZRP1cojlBHBce9xrylhR-rbv3Wg&#39;;return true;">http://blog.bukn.info
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="QQdRYKmcEgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">wxpython-user...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Button overlaying text

dncarac
In reply to this post by Robin Dunn
That is precisely what I'd like.  Thanks for the suggestion.  I'll try that and report back

On Monday, January 14, 2019 at 9:44:40 AM UTC-8, Robin Dunn wrote:
On Monday, January 14, 2019 at 8:46:59 AM UTC-8, Robin Dunn wrote:
On Sunday, January 13, 2019 at 1:55:48 PM UTC-8, dncarac wrote:
As part of a game I"m working on, I want a dialog with a static text control, with a relatively small button which is placed at random locations atop the text.  I can do this in TKinter and QT, but they have problems with unittesting.  I tried this with wxPython, but it doesn't work.  I'm assuming I did something wrong since it is so easy to do in the other frameworks.  Here is the code I've tried:
import wx
wxApp
= wx.App()
dlg
= wx.Dialog(None)
btn
= wx.Button(dlg, label="Button")
txt
= wx.StaticText(dlg, label="Static text", size=dlg.GetClientSize())
dlg
.Show()
wxApp
.MainLoop()
What it does is display a dialog with text, but the button doesn't appear until the mouse is moved over the button, then the button appears. I've tried wx.Raise() the button, and wx.Lower() the text and both - no change.  I"ve tried changing the order of the txt and btn lines.  I've tried wx.Frame instead of wx.Dialog - no change.  I tried a Frame with an included Panel - didn't work.


The behavior of overlapping sibling widgets (have the same parent and occupy the same area) is undefined in wxWidgets. If you want the button to hide the text when it is active then call the static text's Hide() method. If what you really want is for them to appear next to each other then you either need to specify positions or use a sizer as others have mentioned. There is no automatic stacking or packing like in some toolkits.

Also, if you do need to keep the text (partially) visible with the button on top of it, then try making the text be the parent widget of the button. This will probably work on Windows, not sure about the others since static text is not intended to be a container widget. Another option would be to draw the text yourself in the panel's EVT_PAINT handler and keep the button as a child of the panel. Then you won't have the overlapping siblings problem.

--
Robin


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Button overlaying text

john fabiani`
In reply to this post by dncarac
Interesting, I didn't realize you did want fixed positions.  Still I would add a panel and then add the controls to the panel using fixed positions.  You can add panels to dialogs.
Johnf

On 01/14/2019 01:49 PM, dncarac wrote:
Randomizing the position of the button is trivial, so I left it out.  If I can't get a button a text to coexist the way I want at fixed positions, I'm still stuck.  I didn't use sizers because they purposely do not overlay widgets.

On Monday, January 14, 2019 at 7:52:55 AM UTC-8, johnf wrote:
Add a couple of panels to dialog along with some sizers.  See the many tutorials on line.  As far as the random placement of the button above the text - I see nothing you are doing to randomize the location of the button.  It's been my experience mixing sizers and positional control does not work very well.  I'll guess that finding the button is part of the game.  Therefore, I would create a thread to handle moving the button.

Johnf

On 01/13/2019 07:45 PM, 张慧聪 wrote:
Maybe you should try to set the pos parameter.
I recommend to use wx.BoxSizer to align your elements

On Mon, Jan 14, 2019 at 5:55 AM dncarac <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="QQdRYKmcEgAJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;" moz-do-not-send="true">paten...@...> wrote:
As part of a game I"m working on, I want a dialog with a static text control, with a relatively small button which is placed at random locations atop the text.  I can do this in TKinter and QT, but they have problems with unittesting.  I tried this with wxPython, but it doesn't work.  I'm assuming I did something wrong since it is so easy to do in the other frameworks.  Here is the code I've tried:
import wx
wxApp
= wx.App()
dlg
= wx.Dialog(None)
btn
= wx.Button(dlg, label="Button")
txt
= wx.StaticText(dlg, label="Static text", size=dlg.GetClientSize())
dlg
.Show()
wxApp
.MainLoop()
What it does is display a dialog with text, but the button doesn't appear until the mouse is moved over the button, then the button appears. I've tried wx.Raise() the button, and wx.Lower() the text and both - no change.  I"ve tried changing the order of the txt and btn lines.  I've tried wx.Frame instead of wx.Dialog - no change.  I tried a Frame with an included Panel - didn't work.

Any help is appreciated.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="QQdRYKmcEgAJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;" moz-do-not-send="true">wxpython-user...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;" moz-do-not-send="true">https://groups.google.com/d/optout.


--
<a href="http://blog.bukn.info" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\x3dhttp%3A%2F%2Fblog.bukn.info\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGZRP1cojlBHBce9xrylhR-rbv3Wg';return true;" onclick="this.href='http://www.google.com/url?q\x3dhttp%3A%2F%2Fblog.bukn.info\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGZRP1cojlBHBce9xrylhR-rbv3Wg';return true;" moz-do-not-send="true">http://blog.bukn.info
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="QQdRYKmcEgAJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;" moz-do-not-send="true">wxpython-user...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;" moz-do-not-send="true">https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Button overlaying text

dncarac
In reply to this post by Robin Dunn
Making the button a child of the static text worked like a charm in Windows.  I don't have access to Linux or Mac, so I can't check those out yet.  I've never drawn text so I have some studying to do.  I'll report back when I've done that.

Again, thanks for the pointers.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Button overlaying text

dncarac
In reply to this post by Robin Dunn
I've now figured out how to draw text.  Not as hard as it looked at first.  This, too, works like a charm.  Thanks Robin.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.