Problem with find

Reply

Join Date: Mar 2006
Posts: 56
Reputation: Blujacker is an unknown quantity at this point 
Solved Threads: 1
Blujacker Blujacker is offline Offline
Junior Poster in Training

Problem with find

 
0
  #1
Mar 16th, 2006
Hi!I have a problem and i think you can help me!(Sorry my english.I learn just one year)
Thats part of my program...
  1. okno=Tk()
  2. text=Text()
  3. text.pack()
  4. def find():
  5. print "I need help here"
  6. menubar = Menu(okno)
  7. editmenu = Menu(menubar, tearoff=0,bd=4)
  8. editmenu.add_command(label="Find", command=find)
  9. menubar.add_cascade(label="Edit", menu=editmenu)
  10. okno.config(menu=menubar)
i need add to definiction find correcet function.I need something like "find" in python GUI.If you press button find,you will see new window.In the window must be an Entry and Button.If you write sometzhing in entry and then press button will be called function:if is entry.get in text,selcet it and set cursor on them.if there is moore, they will by show by oressing button.I have tryied program from code snipet find, but i didnt solved it.
Thanks.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 56
Reputation: Blujacker is an unknown quantity at this point 
Solved Threads: 1
Blujacker Blujacker is offline Offline
Junior Poster in Training

Re: Problem with find

 
0
  #2
Mar 16th, 2006
or just say how to selcet some text and how to set curor
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 138
Reputation: a1eio is an unknown quantity at this point 
Solved Threads: 21
a1eio's Avatar
a1eio a1eio is offline Offline
Junior Poster

Re: Problem with find

 
0
  #3
Mar 16th, 2006
hi,

The following code is the find function part of your code but with part of the solution
it now prints the index (location) of the begining of a string or letter but i havn't a clue how to highlight text.

  1. def find():
  2. findStr = tkSimpleDialog.askstring("Find", "Find:") # Prompts user to enter a string, if nothing is entered, function returns None
  3. if findStr: # Test to see if the function returned a string or None
  4. print findStr
  5. start = 1.0
  6. while 1:
  7. position = text.search(findStr, start, stopindex=END)
  8. if not position:
  9. break
  10. print "string was found at ", position
  11. start = position + "+1c"
  12. else:
  13. print 'nothing was entered'

the text widget uses index's, 1.0 would mean the first row (1) and the first column (0)
just picture the text widget as a grid, with one character in each square

so when you enter a string to search, it returns either nothing (if nothing was found) or the index for the first character in the string.

at the end of the while loop, the "+1c" means +1 column.

www.pythonware.com has documentation for all of Tkinter
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 56
Reputation: Blujacker is an unknown quantity at this point 
Solved Threads: 1
Blujacker Blujacker is offline Offline
Junior Poster in Training

Re: Problem with find

 
0
  #4
Mar 16th, 2006
Thanks :lol: .But maybe can asnwer me somebody else.How to set cursor on some index?and what about select it? :eek:
I thanks to all! :p
Thats nice forum
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC