How to take user input in matplotlib? - python

Is there any way of getting some input from a user in matplotlib? For example, a drop down list or a text box? What alternatives are there?
If there isn't anything, what would be the easiest way of displaying data based on what a user's input would be?

This could be a very very WIDESPREAD answer...
What exactly do you mean when you say "input from user?"
if you are just talking about a textbox and an okay button then
raw_input('Enter your text')
If you're wanting something a bit more sophisticated and controllable I suggest looking into the Tkinter tools and creating your own GUI where you can create things like combo boxes, checkboxes, entry widgets, popup boxes, and a lot more.
if this doesn't exactly answer what you are asking please post an example of your code then add something like
code code code
#HERE YOU WOULD PUT WHAT YOU WANT TO ACCOMPLISH
code code code

Related

Taking input from text boxes

I've looked at the documentation of Starlette, and can't seem to figure out how to take the content of a text box and link it to a python variable. The plan is to have a user enter text into several text boxes, click a button, and then the information will be used for an SQL query.
I really have no idea how to proceed.
Edit: I think people are misunderstanding. There is no code yet. I don't know how to reference a text box using Starlette.

Button Click Event giving errors - do I need classes?

Trying my first foray into Python and TkInter, and have already gotten some great help here. However, I'm hitting another wall and hoping somebody here can give me a lift to the other side.
My app is pretty simple, conceptually. Just a page with 10-20 rows of labels next to text boxes and option menus (with about 25 items, all identical).
All I want to do is add SUBMIT and QUIT buttons. But, as with most things I'm trying, I get errors every step of they way.
SubmitButton = Button(root, text="Submit", command=greetings)
SubmitButton.place(x=700, y=600)
def greetings():
print("Hello there")
The error (on this particular example) is
NameError: name 'greetings' is not defined
But isn't that what def greetings() does?
Most of the examples I'm seeing refer to things like self/master/frame, but I don't have any of that stuff in my script (at least not explicitly).
Isn't there some easy way to create a custom function and call that function on the click event? Or do I have to go back to the drawing board and try to understand how to use classes and such?
I'm using Python 3.6 and Spyder if that makes any difference.
Thank you for any guidance.
I'm not sure why it's not printing to the console on button push and without seeing your updated snippet I wouldn't be able to tell.
However, the below snippet does work for me and should demonstrate how to handle custom functions on buttons:
from tkinter import *
root = Tk()
def greetings():
print("Hello there")
SubmitButton = Button(root, text="Submit", command=greetings)
SubmitButton.pack()
Also, to answer your question. No, you don't need to use classes or any form of object orientation. However, when it comes to tkinter (and yes this is heavily opinion based) it is often easier to use classes, there are countless reasons why this is and there are plenty of questions and answers on and off this site as to why this is.
This answer probably has the best explanation as to why this is.

I'm starting out using tkinter

I am just starting out to use tkinter in Python 3.5 and I don't understand it the best yet but hopefully will over time.
Anyway, what I was asking was how do I create a text box that a user can type into, I know it is possible but don't yet know how to execute this as, as I said at the beginning, I'm just starting out.
If there is any scaffolding code of a box that I could use to that would allow a user to enter text, it would be a great help if you could show it to me.
Also, to interact with this input, would it be the same as python?
I know this is a lot to be asking but any responses are welcome,
Thanks in advance :)
Both of the following links contain code relating to text entry.
http://effbot.org/tkinterbook/entry.htm
http://effbot.org/tkinterbook/text.htm
Entry is a single line box.
Text is a multiple line box and supports text formatting

matplotlib interactive alteration of line properties

I've been looking for a graphical / ipython console based means to turn lines on and off in a 2D graph generated with matplotlib, but I haven't found anything thus far.
Does anyone know a way to do something like this? What I have in mind specifically is incorporated in MATLAB, and can be seen here:
http://matlab.izmiran.ru/help/techdoc/creating_plots/plot_to5.html
All of the check boxes in the plot browser window will turn the lines on and off; their properties can also be altered graphically in another dialogue box. For now, I've been clicking on the properties button, and setting linetype to none, but this is cumbersome for a graph with many lines...
Thanks Vadim for your answer - you're right that the widgets provide an example with this functionality - to an extent. The example you provide doesn't give the graphical feedback I had in mind; instead, the widgets example closest to my request is actually check_buttons.py (see: http://matplotlib.org/examples/widgets/check_buttons.html)
Here, a side-box of labelled check buttons can be created, where upon clicking the checked buttons, it will turn the lines on and off - see the figure below. I suppose this could be built up into something along the lines of a plot browser like in matlab, but would require additional work to incorporate simple changes to the line style, etc.
I am still interested to know if someone has already done all of the work in making such functionality available; if not, I will post my best attempt when I get around to it.
plot_browser
I don't have sufficient rep points to add the image inline; my apologies.
Yes, there exists module named matplotlib.widgets. There are some example here. It allows you to do exactly what you asked for (source):

making a python gui for ffdshow

I was thinking that for a learning project for myself, I would try to make a GUI for ffdshow on linux, using tkinter. Wanted to make sure this project would be feasible first, before I get halfway through and run into something that cant be done in python.
Basic idea is to have a single GUI window with a bunch of drop down boxes that have the various presets (like format or bitrate), as well as a text box where a custom number can be entered if applicable. Then when all the options are selected, the user hits the Start button on the GUI and it shows a progress little bar with a percentage. All the options selected would just send the relevant selections as cli arguments for ffdshow, and begin the conversion progress (essentially turning all the user's input into a single perfect cli command).
Is all this doable with python and tkinter? and is it something that a relative newb with only very basic tkinter experience could pull off with books and other python resources?
Thanks
That is precisely the type of thing that python and Tkinter excel at. And yes, a relative newbie can easily do a task like that.

Categories