Create Funcion

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

Create Funcion

rausson.gouveia
I want each DEF to represent a Menu. But I can not. Help me
import wx

class Tela(wx.Frame):

def __init__(self, *args, **kwa):
super(Tela, self).__init__(*args, **kwa)
self.Centre()
self.SetTitle("Halzon")
self.SetSize((800,500))
self.FUN()
self.FUN1()


def FUN(self):
menubar = wx.MenuBar()
menu = wx.Menu()

menubar.Append(menu, "NetWork")

menu.Append(wx.NewId(), "Scan")
self.SetMenuBar(menubar)

def FUN1(self):
funBar = wx.MenuBar()
fun = wx.Menu()

funBar.Append(fun, "Web")

fun.Append(wx.NewId(),"DataB")
self.SetMenuBar(funBar)

def main():
app = wx.App()
frame = Tela(None)
frame.Show()
app.MainLoop()
main()

--
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: Create Funcion

Claudia Frank
Normally you only have one MenuBar and multiple Menus.
So something like this

    def __init__(self, *args, **kwa):
       
super(Tela, self).__init__(*args, **kwa)
       
self.Centre()
       
self.SetTitle("Halzon")
       
self.SetSize((800,500))
       
self.menubar = wx.MenuBar()
       
self.FUN()
       
self.FUN1()
       
self.SetMenuBar(self.menubar)

   
def FUN(self):
        menu
= wx.Menu()
       
self.menubar.Append(menu, "NetWork")
        menu
.Append(wx.NewId(), "Scan")

   
def FUN1(self):
        fun
= wx.Menu()
       
self.menubar.Append(fun, "Web")
        fun
.Append(wx.NewId(),"DataB")

Cheers
Claudia

Am Montag, 5. November 2018 16:52:36 UTC+1 schrieb [hidden email]:
I want each DEF to represent a Menu. But I can not. Help me
import wx

class Tela(wx.Frame):

def __init__(self, *args, **kwa):
super(Tela, self).__init__(*args, **kwa)
self.Centre()
self.SetTitle("Halzon")
self.SetSize((800,500))
self.FUN()
self.FUN1()


def FUN(self):
menubar = wx.MenuBar()
menu = wx.Menu()

menubar.Append(menu, "NetWork")

menu.Append(wx.NewId(), "Scan")
self.SetMenuBar(menubar)

def FUN1(self):
funBar = wx.MenuBar()
fun = wx.Menu()

funBar.Append(fun, "Web")

fun.Append(wx.NewId(),"DataB")
self.SetMenuBar(funBar)

def main():
app = wx.App()
frame = Tela(None)
frame.Show()
app.MainLoop()
main()

--
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: Create Funcion

rausson.gouveia
In reply to this post by rausson.gouveia
 Thank you Claudia, I'll do it the way you said, but I have another problem. if I want to open another frame by clicking on the (ex: network) or scan. How should I do it ?? Why do I want to make it open another screen if I click on SubMenus

import wx

class Tela(wx.Frame):

def __init__(self, *args, **kwa):
super(Tela, self).__init__(*args, **kwa)
self.Centre()
self.SetTitle("Halzon")
self.SetSize((800,500))
self.FUN()
self.FUN1()


def FUN(self):
menubar = wx.MenuBar()
menu = wx.Menu()

menubar.Append(menu, "NetWork")

menu.Append(wx.NewId(), "Scan")
self.SetMenuBar(menubar)


def main():
app = wx.App()
frame = Tela(None)
frame.Show()
app.MainLoop()
main()

--
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: Create Funcion

Claudia Frank
You can do it in the same way as you already did with Tela frame class.

Define a new frame

class B(wx.Frame):
   
def __init__(self, *args, **kwa):
       
super(B, self).__init__(*args, **kwa)
       
self.SetTitle("B Frame")
       
self.SetSize((400,200))

bind an menu event to a function like

    def FUN(self):
        menu
= wx.Menu()
       
self.menubar.Append(menu, "NetWork")
        menu
.Append(101, "Scan")
       
self.Bind(wx.EVT_MENU, self._scan, id=101)

create the function which shows the frame

    def _scan(self, event):
        B
(None).Show()

Btw. do you know the wxPython demos? They could be very helpful. See here.

Cheers
Claudia

--
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: Create Funcion

rausson.gouveia
In reply to this post by rausson.gouveia
Claudia I did as you said, but the code still looks like 3 error: I'm sorry, I'll call you for your help every time. I've seen the Phoenix link and it's very good. I'm new to wxPython. I started a few weeks ago.

I'll send the code to you

Thank you very much for your attention !!!!

--
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.

teste.py (889 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Create Funcion

Claudia Frank

No, looks like I wasn't clear enough.
It should be more like this

import wx

class Tela(wx.Frame):

   
def __init__(self, *args, **kwa):
       
super(Tela, self).__init__(*args, **kwa)
       
self.SetTitle("Halzon")
       
self.SetSize((600,300))
       
self.Centre()
       
self.FUN()
       
self.SetBackgroundColour("white")
       
   
def FUN(self):
        menubar
= wx.MenuBar()
        menu0
= wx.Menu()
        menubar
.Append(menu0, "Net")
        menu0
.Append(101, "Scan")
       
self.Bind(wx.EVT_MENU, self._scan, id=wx.ID_ANY)
       
self.SetMenuBar(menubar)

   
def _scan(self, event):
        B
(None).Show()

class B(wx.Frame):
   
def __init__(self, *args, **kwa):
       
super(B, self).__init__(*args, **kwa)
       
self.SetTitle("B Frame")
       
self.SetSize((400, 200))



def main():
    app
= wx.App()
    frame
= Tela(None)
    frame
.Show()
    app
.MainLoop()
main
()

Cheers
Claudia

--
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: Create Funcion

rausson.gouveia
In reply to this post by rausson.gouveia
Hello claudia I need your help !! My situation is this ... I did the functions and now I have to make each subMenu open the different Frame
ex: Net >> Scan = Fame B
eg: Map >> GPS = frame C
I've been trying for days, but I do not know what to do. I think it's something simple. But.... this is my code

--
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.

MenuFun01.py (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Create Funcion

rolfofsaxony
You have bound both menu items to the same ID i.e. 101
You can either use different hardcoded Id's i.e.

#Aqui voçe ira coloca seus SubMenus representado os Menus principais
        menu0.Append(101, "Scan")
        self.Bind(wx.EVT_MENU, self._scan, id=101)
        self.SetMenuBar(menubar)

        menu1.Append(102, "GPS")
        self.Bind(wx.EVT_MENU, self._GPS, id=102)
        self.SetMenuBar(menubar)

or you can use wx.ID_ANY and bind the menu items specifically i.e.

#Aqui voçe ira coloca seus SubMenus representado os Menus principais
        menu0.Append(wx.ID_ANY, "Scan")
        menu0.Bind(wx.EVT_MENU, self._scan)
        self.SetMenuBar(menubar)

        menu1.Append(wx.ID_ANY, "GPS")
        menu1.Bind(wx.EVT_MENU, self._GPS)
        self.SetMenuBar(menubar)

There are a number of ways to do it but using the identical ID is your problem.
regards
Rolf

On Saturday, December 1, 2018 at 11:50:18 PM UTC+1, [hidden email] wrote:
Hello claudia I need your help !! My situation is this ... I did the functions and now I have to make each subMenu open the different Frame
ex: Net >> Scan = Fame B
eg: Map >> GPS = frame C
I've been trying for days, but I do not know what to do. I think it's something simple. But.... this is my code

--
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: Create Funcion

rausson.gouveia
it was just to change the id and the numbers. I knew it was a simple thing. but the smallest details cause the biggest problems. Thank you very much rolfofsaxony !!

Livre de vírus. www.avast.com.

Em dom, 2 de dez de 2018 às 06:43, rolfofsaxony <[hidden email]> escreveu:
You have bound both menu items to the same ID i.e. 101
You can either use different hardcoded Id's i.e.

#Aqui voçe ira coloca seus SubMenus representado os Menus principais
        menu0.Append(101, "Scan")
        self.Bind(wx.EVT_MENU, self._scan, id=101)
        self.SetMenuBar(menubar)

        menu1.Append(102, "GPS")
        self.Bind(wx.EVT_MENU, self._GPS, id=102)
        self.SetMenuBar(menubar)

or you can use wx.ID_ANY and bind the menu items specifically i.e.

#Aqui voçe ira coloca seus SubMenus representado os Menus principais
        menu0.Append(wx.ID_ANY, "Scan")
        menu0.Bind(wx.EVT_MENU, self._scan)
        self.SetMenuBar(menubar)

        menu1.Append(wx.ID_ANY, "GPS")
        menu1.Bind(wx.EVT_MENU, self._GPS)
        self.SetMenuBar(menubar)

There are a number of ways to do it but using the identical ID is your problem.
regards
Rolf

On Saturday, December 1, 2018 at 11:50:18 PM UTC+1, [hidden email] wrote:
Hello claudia I need your help !! My situation is this ... I did the functions and now I have to make each subMenu open the different Frame
ex: Net >> Scan = Fame B
eg: Map >> GPS = frame C
I've been trying for days, but I do not know what to do. I think it's something simple. But.... this is my code

--
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: Create Funcion

Chris Barker - NOAA Federal
See the style Guide:


number 3 is "don't use explicit IDs" :-)

BTW, that was written along time ago -- it could use an update for Phoenix if someone wants to take it on!

-CHB


On Sun, Dec 2, 2018 at 10:52 AM Rausson Gouveia <[hidden email]> wrote:
it was just to change the id and the numbers. I knew it was a simple thing. but the smallest details cause the biggest problems. Thank you very much rolfofsaxony !!

Livre de vírus. www.avast.com.

Em dom, 2 de dez de 2018 às 06:43, rolfofsaxony <[hidden email]> escreveu:
You have bound both menu items to the same ID i.e. 101
You can either use different hardcoded Id's i.e.

#Aqui voçe ira coloca seus SubMenus representado os Menus principais
        menu0.Append(101, "Scan")
        self.Bind(wx.EVT_MENU, self._scan, id=101)
        self.SetMenuBar(menubar)

        menu1.Append(102, "GPS")
        self.Bind(wx.EVT_MENU, self._GPS, id=102)
        self.SetMenuBar(menubar)

or you can use wx.ID_ANY and bind the menu items specifically i.e.

#Aqui voçe ira coloca seus SubMenus representado os Menus principais
        menu0.Append(wx.ID_ANY, "Scan")
        menu0.Bind(wx.EVT_MENU, self._scan)
        self.SetMenuBar(menubar)

        menu1.Append(wx.ID_ANY, "GPS")
        menu1.Bind(wx.EVT_MENU, self._GPS)
        self.SetMenuBar(menubar)

There are a number of ways to do it but using the identical ID is your problem.
regards
Rolf

On Saturday, December 1, 2018 at 11:50:18 PM UTC+1, [hidden email] wrote:
Hello claudia I need your help !! My situation is this ... I did the functions and now I have to make each subMenu open the different Frame
ex: Net >> Scan = Fame B
eg: Map >> GPS = frame C
I've been trying for days, but I do not know what to do. I think it's something simple. But.... this is my code

--
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.


--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[hidden email]

--
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.