I do a program with a Bitmap Button and i want when i click on my button open a popupmenu. However when i click on my button my program.pyw stop (bug).
Can you tell me why please:
My program: - import wx
-
import wx.lib.buttons as buttons
-
-
class FenetrePrincipal(wx.Frame):
-
def __init__(self, parent, ID, title):
-
wx.Frame.__init__(self, parent, ID, title, wx.DefaultPosition, wx.Size(482, 68), style= wx.FRAME_NO_TASKBAR | wx.STAY_ON_TOP )
-
-
#Bouton Option
-
bmpOption = wx.Bitmap('btn_option.png',wx.BITMAP_TYPE_PNG)
-
self.btnOption = buttons.GenBitmapButton(self, -1, bmpOption, pos = (2,24),size= (18,18), style=wx.BORDER_NONE)
-
self.btnOption.SetToolTipString("Options")
-
self.Bind(wx.EVT_BUTTON, self.OnOption, self.btnOption)
-
-
-
def OnOption(self,event):
-
self.PopupMenu(self.MenuOptions())
-
-
def MenuOptions(self):
-
print "aa"
-
-
class MyApp(wx.App):
-
def OnInit(self):
-
fen = FenetrePrincipal(None, -1, "aaaa")
-
fen.Show(True)
-
self.SetTopWindow(fen)
-
return True
-
-
app = MyApp()
-
app.MainLoop()
-
2 1321
I found a solution so when i click on the menu for the first time nothing happen and after it work... - import wx
-
import wx.lib.buttons as buttons
-
-
class FenetrePrincipal(wx.Frame):
-
def __init__(self, parent, ID, title):
-
wx.Frame.__init__(self, parent, ID, title, wx.DefaultPosition, wx.Size(482, 68), style= wx.FRAME_NO_TASKBAR | wx.STAY_ON_TOP )
-
-
#Bouton Option
-
bmpOption = wx.Bitmap('btn_option.png',wx.BITMAP_TYPE_PNG)
-
self.btnOption = buttons.GenBitmapButton(self, -1, bmpOption, pos = (2,24),size= (18,18), style=wx.BORDER_NONE)
-
self.btnOption.SetToolTipString("Options")
-
self.Bind(wx.EVT_BUTTON, self.OnOption, self.btnOption)
-
-
-
def OnOption(self,event):
-
menu= wx.Menu()
-
menu.Append(101, "Options")
-
self.PopupMenu(menu)
-
-
class MyApp(wx.App):
-
def OnInit(self):
-
fen = FenetrePrincipal(None, -1, "aaaa")
-
fen.Show(True)
-
self.SetTopWindow(fen)
-
return True
-
-
app = MyApp()
-
app.MainLoop()
-
Create the menu early and keep a reference to it: - import wx
-
import wx.lib.buttons as buttons
-
-
class FenetrePrincipal(wx.Frame):
-
def __init__(self, parent, ID, title):
-
wx.Frame.__init__(self, parent, ID, title, wx.DefaultPosition, wx.Size(482, 68), style= wx.FRAME_NO_TASKBAR | wx.STAY_ON_TOP )
-
-
#Bouton Option
-
## bmpOption = wx.Bitmap('btn_option.png',wx.BITMAP_TYPE_PNG)
-
## self.btnOption = buttons.GenBitmapButton(self, -1, bmpOption, pos = (2,24),size= (18,18), style=wx.BORDER_NONE)
-
self.btnOption = wx.Button(self, -1, pos=(2,24), size=(18,18), style=wx.BORDER_NONE)
-
self.btnOption.SetToolTipString("Options")
-
self.Bind(wx.EVT_BUTTON, self.OnOption, self.btnOption)
-
menu= wx.Menu()
-
menu.Append(101, "Options")
-
self.myMenu = menu
-
-
-
def OnOption(self,event):
-
self.PopupMenu(self.myMenu)
-
-
class MyApp(wx.App):
-
def OnInit(self):
-
fen = FenetrePrincipal(None, -1, "aaaa")
-
fen.Show(True)
-
self.SetTopWindow(fen)
-
return True
-
-
app = MyApp()
-
app.MainLoop()
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Joseph |
last post by:
Hi
I'm writing a commercial program which must be reliable. It has to do
some basic reading and writing to and from files on the hard disk,
and also to a floppy.
I have foreseen a potential...
|
by: Eric Brunel |
last post by:
Hi all,
I was creating a Tkinter widget in the style of the reversed tabs below Excel
worksheets and I stepped in a serious problem: the code I made makes python
crash with a seg fault, bus...
|
by: xixi |
last post by:
i have db2 udb v8.1 on windows 64 bit 2003 server, after db2 server
start , i found this in the db2diag.log, is this error?
2004-05-05-15.28.30.780000 Instance:DB2 Node:000...
|
by: NewToCPP |
last post by:
Hi,
Why does a C/C++ programs crash?
When there is access to a null pointer or some thing like that programs
crash, but why do they crash?
Thanks.
|
by: Dennis |
last post by:
A dumb question but what is the difference between the two properties;
ContextMenu and PopMenu?
--
Dennis in Houston
|
by: benjamin.krulewitch |
last post by:
I'm debugging an issue with a C program that causes the computer to
crash, and I'm attempting to log information immediately before the
crash occurs. I us my BKprintLog function (see below) to...
|
by: alf |
last post by:
Hi,
is it possible that due to OS crash or mysql itself crash or some e.g.
SCSI failure to lose all the data stored in the table (let's say million
of 1KB rows). In other words what is the worst...
|
by: palani ganesh |
last post by:
hi all,
i m ganesh a newbie to this site........ In my program i want to insert, delete items in the listcontrol using the popmenu.....Is ther anyone to help me out????
awaiting for ur...
|
by: bruce628 |
last post by:
I want to use SWT Label and popmenu to construct a menubar ,and the effect
of this menubar is same to the menubar in SWT.When click the Label,it should be highlighted and popmenu shows.The issue is...
|
by: =?Utf-8?B?R2VyaGFyZA==?= |
last post by:
I have run into a situation that if a page/tab that uses the Ajax toolkit
(using .net version 3.5) is closed before the Ajax enable controls complete
loading, then IE locks up. Does it in both IE7...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |