2 Replies - 1280 Views - Last Post: 13 September 2012 - 09:26 PM Rate Topic: -----

#1 og_the_trog  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 12-September 12

wx.TextEntryDialog box in a wx.Frame

Posted 12 September 2012 - 10:29 PM

hello I am new to python/wxpython (and programming) and thought I would just start off by creating a small G.U.I, here is my code and I'll explain what it does after.
import wxversion
wxversion.select('2.8')

import wx
class build (wx.Frame):
    
    def __init__ (self,parent,id):
        wx.Frame.__init__(self,parent,id,"Dictionary", size= (700,500))
        panel = wx.Panel(self)

        pic = wx.Image('C:/Users/bob/Desktop/programs/python/Search Dictionary.bmp', wx.BITMAP_TYPE_ANY).ConvertToBitmap()
        self.button=wx.BitmapButton(panel, -1, pic, pos=(180,10))
        self.Bind (wx.EVT_BUTTON, self.SearchDictionary, self.button)
        self.button.SetDefault()
         
    def SearchDictionary(self, event):
        
        box = wx.TextEntryDialog(None,"What's the word you wish to look up? (Lower-Case)", "Dictionary", "")
        if box.ShowModal() == wx.ID_OK: 
            answer = box.GetValue

        if answer() == "1":
        
            wx.StaticText(self, -1, "Example Text 1  ", (30,100))

        if answer() == "2":
            wx.StaticText(self,-1,"Example Text 2 ", (30,100))

    def closewindow(self, event):
        self.Destroy()


if __name__=="__main__":
    app=wx.PySimpleApp()
    frame=build(parent=None,id=-1)
    frame.Show()
    app.MainLoop() 


So at the moment it creates a frame with a bitmap button on it and when you press it, it brings up a wx.TextEntryDialog window. Then when you choose your word it saves it and prints out the certain wx.StaticText that i have specially written to that word. What I want to do though is get rid of the bitmap button completely and have the dialog box in the frame instead of a separate window, like how Google have there website.

Is This A Good Question/Topic? 0
  • +

Replies To: wx.TextEntryDialog box in a wx.Frame

#2 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 319
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: wx.TextEntryDialog box in a wx.Frame

Posted 13 September 2012 - 12:03 AM

The text entry box is basically a wx.TextCtrl and an "Ok" and "Cancel" button in a dialog, it's one of the general purpose ones provided by wxPython - you didn't have to write the layout or Bind any of the buttons, for example.

To have it on a single frame you need to make a wx.TextCtrl and two "Ok" and "Cancel" wx.Buttons, you will need to look at layout management if you haven't already.

And the "Ok" button will take the place of the self.SearchDictionary binding:

self.Bind(wx.EVT_BUTTON, self.SearchDictionary, okButton)


Then your search dictionary method will look something like:
    def SearchDictionary(self, event):
        
        # here I assume the wx.TextCtrl is called "textCtrlBox" and is a self attribute
        answer = self.textCtrlBox.GetValue()

        if answer() == "1":
        
            wx.StaticText(self, -1, "Example Text 1  ", (30,100))

        if answer() == "2":
            wx.StaticText(self,-1,"Example Text 2 ", (30,100))



Are you aware the close window method isn't bound to anything in that code? Maybe you want the cancel button to close the window? You'd do something like:
self.Bind(wx.EVT_BUTTON, self.closewindow, cancelButton)



PS: I'm not able to write any code right now but later on, I'll write a nice example for you (if no one else beats me to it ;))

PPS: This is a good basic tutorial: http://zetcode.com/wxpython/, and the wxPython site documentation is great!

This post has been edited by Simown: 13 September 2012 - 12:55 AM
Reason for edit:: Fixed syntax. I wish wxPython used camel case

Was This Post Helpful? 0
  • +
  • -

#3 og_the_trog  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 12-September 12

Re: wx.TextEntryDialog box in a wx.Frame

Posted 13 September 2012 - 09:26 PM

Thank you soooo much this was really helpful and thanks for all the suggestions as well.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1