0

I have created a setting window in python where i have a few path settings which has to be one time setting.Here is the sample demo code,

import wx
import os
class SettingWindow(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)
        panel= wx.Panel(self,-1)
        font = wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD)
        field1 = wx.TextCtrl(panel,pos=(120,25),size=(170,20))
        vsizer = wx.BoxSizer(wx.VERTICAL)
        field1_sz=wx.BoxSizer(wx.HORIZONTAL)
        field2_sz=wx.BoxSizer(wx.HORIZONTAL)
        field1_lbl=wx.StaticText(panel,-1, label='Repo URL path:', pos=(25, 25))
        field1_lbl.SetFont(font)
        field1_sz.AddSpacer(50)
        field1_sz.Add(field1_lbl)
        field1_sz.AddSpacer(5) # put 5px of space between
        field1_sz.Add(field1)
        field1_sz.AddSpacer(50)

        vsizer.AddSpacer(50)
        vsizer.Add(field1_sz)
        vsizer.AddSpacer(15)
        vsizer.Add(field2_sz)
        vsizer.AddSpacer(50)

        btn1 = wx.Button(panel, label='Browse',pos=(300,25),size=(60,20))
        btn1.Bind(wx.EVT_BUTTON, self.opendir)

    def opendir(self, event):
        dlg = wx.DirDialog(self, "Choose a directory:", style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON)
        if dlg.ShowModal() == wx.ID_OK:
            field1.SetValue("%s",dlg.GetPath())

        dlg.Destroy()




class MyApp(wx.App):
    def OnInit(self):
        frame= SettingWindow(None,-1,'Setting Window')
        frame.Show()
        self.SetTopWindow(frame)
        return True
app= MyApp(0)
app.MainLoop()

I want to display the path which i get from opendir in textCtrl.I am finding an error like below, Traceback (most recent call last): File "D:\PROJECT\SettingWindow.py", line 58, in opendir return (field1) NameError: global name 'field1' is not defined

1
  • can anyone please let me know how to make the text field disable when checked on checkbox and how to pass the value(in above case is the path) in the checkbox to the other class where the function takes that value. Commented Feb 20, 2013 at 4:42

2 Answers 2

1

use self.field1 instead of variable field1:

self.field1 = wx.TextCtrl(panel,pos=(120,25),size=(170,20))

self.field1.SetValue(dlg.GetPath())
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much.It worked.How would i make the selected path default using checkbox?
Oh, sorry, I didn't know what you mean. Can you describe it for more detail?
According to the above code, i have a directory path in field1. Now i need to make it default making the TextCtrl disable by clicking on the checkbox and pass the input path to other class.
1

This code works to make the TextCtrl field hidden when clicked on the checkbox

def OnCheckBox(self,event):
    if self.checkbox.Value==False:
        self.field.Enable(True)
    else:
        self.field.Enable(False)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.