Is it possible to create default values with EasyGui multenterbox? - python

I have an EasyGui multenterbox and I was wondering if there was a way to set a default value for the inputs in the GUI?
Thanks

Probably you need default_text argument
Syntax : enterbox(message, title, default_text)
Argument : It takes 3 arguments, first string i.e message/information to be displayed, second string i.e title of the window and third is string which is default text
Return : It returns the entered text and None if cancel is pressed
EasyGui default text

Related

Automatically populate python input prompt with default value

The code:
input("Type your input here:)
displays as:
Type your input here:
I want to automatically populate the input window with text that can be cleared by pressing backspace so the display looks like:
Type your input here: DEFAULT
and after pressing backspace 3 times the user would see:
Type your input here: DEFA
Other posts have indicated that this isn't something you can do in, say, bash, but is there a way to do this in Python?
Simple answer: No. It's just not something you can do in a console app. What's commonly done is to display the default you'll get if you press return:
Type your input here [DEFAULT]:

Is there an pysimplegui function to get the the loction of the input cursor?

I am making an application which includes a form, at some point, I have a multiline element that must be filled by the user and I need the cursor location because the user must indicate after a specific text location of the multiline element.
I have try to access to the Tkinter method : print(t.index(tk.INSERT)) , but I got stuck.
Thanks for the help.
Assuming t is your PySimpleGUI element, t.Widget should give you access to the underlying Tkinter widget.
print(t.Widget.index(tk.INSERT))

Tkinter Find and Replace Function for Notepad

I'm new at Tkinter, and python. I've been experimenting with a notepad script I've made. I'm working on a find / replace command. But I've had no luck. Here is what I've tried so far:
def replace():
def replaceall():
findtext = str(find.get(1.0, END))
replacetext = str(replace.get(1.0, END))
alltext = str(text.get(1.0, END))
alltext1 = all.replace(findtext, replacetext)
text.delete(1.0, END)
text.insert('1.0', alltext1)
replacebox =Tk()
replacebox.geometry("230x150")
replacebox.title("Replace..")
find = Text(replacebox, height=2, width=20).pack()
replace = Text(replacebox, height=2, width=20).pack()
replaceallbutton = Button(replacebox, text="Replace..", command=replaceall)
replaceallbutton.pack()
(this is just the function I am defining for the replace command)
The 'text' variable is on the large canvas which contains the menu's and the main text widget.
Any help is appreciated
So far I've been creating this notepad in 2.7.8, so the Tkinter import is 'Tkinter.'
What I'm shooting for is having the first box have the text to find and the second box have the text to be replaced. Upon pressing the replace button, the function replaceall() should begin.
Are there any obvious mistakes in my function, or is it just deeply flawed? Any help is appreciated.
The most obvious mistake is that you are creating a second instance of Tk. If you need a popup window you should create an instance of Toplevel. You should always have exactly one instance of Tk running.
The second problem is related to the fact you are using a Text widget for the find and replace inputs. When you do a get with a second index of END, the string you get back will always have a newline whether the user entered one or not. If you want exactly and only what the user typed, use "end-1c" (end minus one character).
Finally, there's no reason to get all the text, replace the string, and then re-insert all the text. That will work only as long as you have no formatting or embedded widgets or images in the text widget. The text widget has a search command which can search for a pattern (either string or regular expression), and you can use the returned information to replace the found text with the replacement text.

Python EasyGui : Returning User Input In TextBoxes

Hello i am currently using python 2.7 to create a GUI based program with the add on library EasyGui. I'm trying to take the user input from a multiline textbox and print those values to another function which displays inside a messagebox. currently my code looks like this:
fieldNames = ["Name","Street Address","City","State","ZipCode"]
fieldValues = []
def multenterbox123():
multenterbox(msg='Fill in values for the fields.', title='Enter', fields=(fieldNames), values=(fieldValues))
return fieldValues
multenterbox123();
msgbox(msg=(fieldValues), title = "Results")
its currently returing a blank value in the messagebox (msgbox) and i understand why its doing this , as its pointing to the blank list variable fieldValues. I actually want to take the list values after its passed in from the user in the multi line textbox (multenterbox123) function, but im having trouble trying to work out how to best implement this.
Any help into this would be greatly appreciated as im only new to python programming (:
from easygui import msgbox, multenterbox
fieldNames = ["Name", "Street Address", "City", "State", "ZipCode"]
fieldValues = list(multenterbox(msg='Fill in values for the fields.', title='Enter', fields=(fieldNames)))
msgbox(msg=(fieldValues), title = "Results")
I tested the code above on my computer and the msgbox returned what I entered in the multenterbox . There is an example in the documentation if you want to take a look at it. Multenterbox-EasyGUI-Documentation. Basically you first need to make a list, hence the list function. And all the values entered will be stored in it. So whatever I write in the multenterbox will be saved in the fieldValues list.

Editing text in a wx.textcontrol with wx validator

I have a validator which Ive attached to a wx.TextCtrl inside a wx.Dialog:
myinput = wx.TextCtrl(self, validator=MyValidator())
All that validator does is it binds a wx.EVT_CHAR event and checks whether the input is a number and whether the number of characters entered is less than 5.
The problem is when I select the text with my mouse i.e. turn it to blue I cant replace the text if the number of characters is already at its maximum.
How can I detect whether the user has selected the text of that specific text box and has pressed a key?
Take a look at how the IntValidator inside the file wx\lib\intctrl.py is created.
Now use the intctrl instead of creating your own and limit the characters entered to 4 by using the method SetMaxLength(4)

Categories

Resources