Note that there are some explanatory texts on larger screens.

plurals
  1. POPython: get a checkbox - the easiest way
    primarykey
    data
    text
    <p>or perhaps the lazy way..</p> <p>I'm looking for a python module that has some build-in GUI methods to get quick user inputs - a very common programming case. Has to work on windows 7</p> <p><strong>My ideal case</strong></p> <pre><code>import magicGUImodule listOfOptions = ["option 1", "option 2", "option 3"] choosenOptions = magicGUImodule.getChecklist(listOfOptions, selectMultiple=True, cancelButton=True) </code></pre> <p>It's kinda like <code>raw_input</code> but with a GUI. There must be something out there since this is a common programming task. </p> <hr> <h2>UPDATE</h2> <p>@alecxe it is not to be rude that I unchecked your answer as the solution to my problem. I still want to be able to use <strong>my ideal case</strong> in whatever script I'm working on and your answer gets me half the way.</p> <p>I thought that I could implement @alecxe's solution easily into a module, but it's not that simple (for me)..</p> <p>Here is my module so far:</p> <pre><code># This serve as a module to get user input - the easy way! # Some GUI selection #from Tkinter import * import Tkinter master = Tkinter.Tk() input = None listbox = None def chooseFromList(list, windowTitle="Choose from list", buttonText="Submit", selectMultiple=False, w=150, h=30): global listbox listbox = Tkinter.Listbox(master, selectmode=MULTIPLE if selectMultiple else SINGLE, width=w, height=h) listbox.master.title(windowTitle) for option in list: listbox.insert(0, option) listbox.pack() #listbox.selection_set(1) b = Tkinter.Button(master, command=callback(listbox), text=buttonText) b.pack() mainloop() def callback(listbox): global listbox setInput(listbox.selection_get()) master.destroy() def setInput(var): global input input = var def getInput(): global input return input </code></pre> <p>And here is my script </p> <pre><code>import GetUserInput listOfOptions = ["option 1", "option 2", "option 3"] choice = GetUserInput.chooseFromList(listOfOptions) print choice.getInput() </code></pre> <p>But I just get the error </p> <p><code>can't invoke "listbox" command: application has been destroyed</code></p> <p>Have tried a lot of different options that I though would solve the case (like using global variable) - but without any luck.</p> <h2>UPDATE 2</h2> <p>@blablatros gave me exactly the solution that I was looking for.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload