473,385 Members | 1,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Popmenu and crash

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:
Expand|Select|Wrap|Line Numbers
  1. import wx
  2. import wx.lib.buttons as buttons
  3.  
  4. class FenetrePrincipal(wx.Frame):
  5.     def __init__(self, parent, ID, title):
  6.         wx.Frame.__init__(self, parent, ID, title, wx.DefaultPosition, wx.Size(482, 68), style= wx.FRAME_NO_TASKBAR | wx.STAY_ON_TOP )
  7.  
  8.         #Bouton Option
  9.         bmpOption = wx.Bitmap('btn_option.png',wx.BITMAP_TYPE_PNG)
  10.         self.btnOption = buttons.GenBitmapButton(self, -1, bmpOption, pos = (2,24),size= (18,18), style=wx.BORDER_NONE)
  11.         self.btnOption.SetToolTipString("Options")
  12.         self.Bind(wx.EVT_BUTTON, self.OnOption, self.btnOption)
  13.  
  14.  
  15.     def OnOption(self,event):
  16.         self.PopupMenu(self.MenuOptions())
  17.  
  18.     def MenuOptions(self):
  19.         print "aa"
  20.  
  21. class MyApp(wx.App):
  22.     def OnInit(self):
  23.         fen = FenetrePrincipal(None, -1, "aaaa")
  24.         fen.Show(True)
  25.         self.SetTopWindow(fen)
  26.         return True
  27.  
  28. app = MyApp()
  29. app.MainLoop()
  30.  
Oct 4 '07 #1
2 1321
I found a solution so when i click on the menu for the first time nothing happen and after it work...
Expand|Select|Wrap|Line Numbers
  1. import wx
  2. import wx.lib.buttons as buttons
  3.  
  4. class FenetrePrincipal(wx.Frame):
  5.     def __init__(self, parent, ID, title):
  6.         wx.Frame.__init__(self, parent, ID, title, wx.DefaultPosition, wx.Size(482, 68), style= wx.FRAME_NO_TASKBAR | wx.STAY_ON_TOP )
  7.  
  8.         #Bouton Option
  9.         bmpOption = wx.Bitmap('btn_option.png',wx.BITMAP_TYPE_PNG)
  10.         self.btnOption = buttons.GenBitmapButton(self, -1, bmpOption, pos = (2,24),size= (18,18), style=wx.BORDER_NONE)
  11.         self.btnOption.SetToolTipString("Options")
  12.         self.Bind(wx.EVT_BUTTON, self.OnOption, self.btnOption)
  13.  
  14.  
  15.     def OnOption(self,event):
  16.         menu= wx.Menu()
  17.         menu.Append(101, "Options")
  18.         self.PopupMenu(menu)
  19.  
  20. class MyApp(wx.App):
  21.     def OnInit(self):
  22.         fen = FenetrePrincipal(None, -1, "aaaa")
  23.         fen.Show(True)
  24.         self.SetTopWindow(fen)
  25.         return True
  26.  
  27. app = MyApp()
  28. app.MainLoop()
  29.  
Oct 4 '07 #2
bartonc
6,596 Expert 4TB
Create the menu early and keep a reference to it:
Expand|Select|Wrap|Line Numbers
  1. import wx
  2. import wx.lib.buttons as buttons
  3.  
  4. class FenetrePrincipal(wx.Frame):
  5.     def __init__(self, parent, ID, title):
  6.         wx.Frame.__init__(self, parent, ID, title, wx.DefaultPosition, wx.Size(482, 68), style= wx.FRAME_NO_TASKBAR | wx.STAY_ON_TOP )
  7.  
  8.         #Bouton Option
  9. ##        bmpOption = wx.Bitmap('btn_option.png',wx.BITMAP_TYPE_PNG)
  10. ##        self.btnOption = buttons.GenBitmapButton(self, -1, bmpOption, pos = (2,24),size= (18,18), style=wx.BORDER_NONE)
  11.         self.btnOption = wx.Button(self, -1, pos=(2,24), size=(18,18), style=wx.BORDER_NONE)
  12.         self.btnOption.SetToolTipString("Options")
  13.         self.Bind(wx.EVT_BUTTON, self.OnOption, self.btnOption)
  14.         menu= wx.Menu()
  15.         menu.Append(101, "Options")
  16.         self.myMenu = menu
  17.  
  18.  
  19.     def OnOption(self,event):
  20.         self.PopupMenu(self.myMenu)
  21.  
  22. class MyApp(wx.App):
  23.     def OnInit(self):
  24.         fen = FenetrePrincipal(None, -1, "aaaa")
  25.         fen.Show(True)
  26.         self.SetTopWindow(fen)
  27.         return True
  28.  
  29. app = MyApp()
  30. app.MainLoop()
Oct 4 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

48
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...
8
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...
10
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...
34
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.
4
by: Dennis | last post by:
A dumb question but what is the difference between the two properties; ContextMenu and PopMenu? -- Dennis in Houston
12
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...
110
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...
1
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...
1
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...
11
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.