RDS
Posts: 721
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Open another window and switch between?

Fri Jun 17, 2016 2:33 pm

I am using Python 3 in IDLE and have a program that monitors my Solar Panels. Ideally I would like to have something like a 'Dashboard type' display but I have no idea how to even start with that (any suggestions very welcome!). In the meantime, my program is listed in one window and when it runs, it opens up another window into which I write information from my sensor. At the moment it just prints out a long list of data and on a good sunny day, this can be up to 30,000 lines long. I would like to be able to write some summary information throughout the day but at the moment this just gets lost in the middle of a long list.

Is it possible to open up another window, write some information and then revert back and forth between the new window and my initial window.

Of course, if I could use a 'dashboard type display' (I hope that is the correct term) it would be even better.

User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: Open another window and switch between?

Fri Jun 17, 2016 2:43 pm

You could try PyGame for a dashboard style display. Would probably be quite a bit of work but nothing tricky.

Dave.
Apple say... Monkey do !!

RDS
Posts: 721
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Re: Open another window and switch between?

Fri Jun 17, 2016 2:56 pm

@davef21370
OK, thank you.
I have heard about PyGame but to be honest I was not sure that it wasn't just a form of game, rather than a means of display.
I will try 'google!'

User avatar
B.Goode
Posts: 8820
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Open another window and switch between?

Fri Jun 17, 2016 3:13 pm

RDS wrote:my program is listed in one window and when it runs, it opens up another window into which I write information from my sensor. At the moment it just prints out a long list of data and on a good sunny day, this can be up to 30,000 lines long. I would like to be able to write some summary information throughout the day but at the moment this just gets lost in the middle of a long list.

Is it possible to open up another window, write some information and then revert back and forth between the new window and my initial window.
As well as, or instead of, writing the data to the standard output channel for the program - which as you have seen is directed back to the screen you are running from - you might consider writing summary information to a 'logging' file. You could then open up another terminal window and monitor what is happening to that file: tail -f is useful for that.

Be aware that IDLE is itself a graphical program written in python. Attempting to run python code that itself generates graphical output from with IDLE can give confusing/frustrating results. Probably better to develop within IDLE if you wish, but test independently from the command line.

User avatar
dasmanul
Posts: 502
Joined: Wed Sep 30, 2015 10:20 am
Location: Frankfurt, Germany

Re: Open another window and switch between?

Fri Jun 17, 2016 3:19 pm

I'm not quite sure I understand what you mean by a "dashboard style" display. Do you have a sketch of what you envision? How are you handling your display/opening a window now? Are you using Tkinter?

RDS
Posts: 721
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Re: Open another window and switch between?

Fri Jun 17, 2016 6:05 pm

dasmanul wrote:I'm not quite sure I understand what you mean by a "dashboard style" display. Do you have a sketch of what you envision? How are you handling your display/opening a window now? Are you using Tkinter?
Thank you for your reply.
I wasn't sure that 'dashboard style' was the correct way to describe it. At present I don't have a sketch of what I envisage but I originally thought I may be able to open another window. From the responses above, I may be better going to my ideal solution that I have described as 'dashboard style'. I mean something that may have dials to indicate numbers or a means of being able to place results in positions or fields in the window but basically anything rather than just a single long list. My window just opens when I run my program because I have some print commands in my program that just produce a list. I am not using Tkinter but I will look up what it is. Would it help me?

RDS
Posts: 721
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Re: Open another window and switch between?

Fri Jun 17, 2016 6:10 pm

B.Goode wrote:... you might consider writing summary information to a 'logging' file. You could then open up another terminal window and monitor what is happening to that file: tail -f is useful for that...
Thanks, That sounds like a possibility and better than I have at present although not my ideal solution. I am not familiar with tail -f

User avatar
dasmanul
Posts: 502
Joined: Wed Sep 30, 2015 10:20 am
Location: Frankfurt, Germany

Re: Open another window and switch between?

Sat Jun 18, 2016 9:19 am

Tkinter is a GUI toolkit that gives you elements like Buttons, Labels, Text Entry fields, Checkboxes etc. you can assemble into a display/GUI for your project, so I think it might indeed help you with what you want. I'll attach an image of my own display I did for my project to give you an idea. Basically, I have some text fields that are updated to reflect current status and change their colour accordingly, and three buttons that open other windows with additional controls. I also display 2 graphics which are produced by an external tool.

Dials and gauges are not natively provided by Tkinter, so for these Pygame might indeed be the better solution. I don't have any experience with that though.
Attachments
2016-06-18-111257_320x480_scrot.png
2016-06-18-111257_320x480_scrot.png (41.68 KiB) Viewed 2931 times

RDS
Posts: 721
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Re: Open another window and switch between?

Sat Jun 18, 2016 9:50 am

@dasmanul
Thank you and that is exactly the type of display I would like to be able to create. Dials and gauges are not really important to me but the text (and later the graphs) that you have shown are exactly what I would like, so Tkinter looks absolutely ideal for my requirements.

Is there a recommended start point, just to get me up and running.
Thanks again,

User avatar
dasmanul
Posts: 502
Joined: Wed Sep 30, 2015 10:20 am
Location: Frankfurt, Germany

Re: Open another window and switch between?

Sat Jun 18, 2016 10:14 am

I'm afraid I used mainly german tutorials, so probably not much help for you. There's a tutorial at http://www.tkdocs.com/tutorial/ and a web search for "Tkinter tutorial" will no doubt turn out many more.

I'm also happy to share my code if you're interested and I'm sure you'll get lots of help here in the forum. This project, started about a month ago, was also my first contact with Tkinter, so everything's still quite fresh.

RDS
Posts: 721
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Re: Open another window and switch between?

Sat Jun 18, 2016 10:41 am

@dasmanul
Thank you again (or should I say Danke) for your support.
You are right that German text would not be of any use to me. Despite over a hundred visits to Germany with work, I was always dealing with people who spoke perfect English, or those who just wanted to practice their English. Unfortunately, I only got as far as being able to order Steak and Chips and a Beer, say Please, Thank you, Good Morning and Goodbye. Shameful really!

If you are able to share your code, I would be very grateful and I will look at the tutorial you have suggested.
I really appreciate the time you have taken to help me.

User avatar
RogerW
Posts: 285
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: Open another window and switch between?

Sat Jun 18, 2016 10:44 am

I have used Tkinter to show graphs and also provide different screens. I do this by overlapping Frames and only showing one at a time. The application is to show system information but you may be able to use similar techniques for your program.

The code is on GitHub
https://github.com/RogerWoollett/PyView

User avatar
dasmanul
Posts: 502
Joined: Wed Sep 30, 2015 10:20 am
Location: Frankfurt, Germany

Re: Open another window and switch between?

Sat Jun 18, 2016 4:21 pm

The complete code for my project is on bitbucket at

https://bitbucket.org/m_reiter/klima

The screenshot is from bin/controller_v3.py. You might also want to look at controller.py and controller_v2.py in the same directory. These are earlier versions which might show you how the GUI gradually evolved towards its current state. Let me know if you have any questions.

RDS
Posts: 721
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Re: Open another window and switch between?

Sat Jun 18, 2016 4:39 pm

@RogerW
Thank you for sharing those links.
I have started with a tutorial that I picked up from http://usingpython.com/using-tkinter/ and I have made quite a bit of progress. tkinter looks ideal for what I wanted.

RDS
Posts: 721
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Re: Open another window and switch between?

Sat Jun 18, 2016 4:43 pm

@dasmanul
As I stated in the post above, I have started on a tutorial that I picked up in a Google search as you suggested. I seem to have made quite a bit of progress in a short time, so thank you for pointing me in the direction of tkinter and thank you for the link to your code.

There are quite a lot of similarities between your example and what I would like to achieve.

User avatar
dasmanul
Posts: 502
Joined: Wed Sep 30, 2015 10:20 am
Location: Frankfurt, Germany

Re: Open another window and switch between?

Sat Jun 18, 2016 4:49 pm

Good luck and have fun then! And don't forget to show us what you come up with! :)

RDS
Posts: 721
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Re: Open another window and switch between?

Sat Jun 18, 2016 5:09 pm

dasmanul wrote:Good luck and have fun then! And don't forget to show us what you come up with! :)
Will do.

User avatar
CarlRJ
Posts: 599
Joined: Thu Feb 20, 2014 4:00 am
Location: San Diego, California

Re: Open another window and switch between?

Sun Jun 19, 2016 5:00 am

As a very quick suggestion, while you're reading up on the various GUI toolkits (tkinter, pygame, etc), try having your script append its raw output (those 30,000 lines you mentioned) to a separate file, and only write periodic summary data (say, the high, low, and accumulated values for the last 15 minutes) to stdout. This will make your second window (the one IDLE is opening for output) much more readable, and if you want to monitor the raw data, you can open a terminal window and read the whole file with "less /path/to/filename" or watch it grow in real time with "tail -f /path/to/filename". That way you'll have your summary info on-screen all the time and the raw data available separately when you want to see it.

Also keep in mind that IDLE is nice for testing, but isn't really a proper way to write/run scripts.

RDS
Posts: 721
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Re: Open another window and switch between?

Mon Jun 20, 2016 6:21 pm

@CarlRJ
Thank you for your reply and I think what you have suggested is a possible way forward, in addition to my use of tkinter for the summary information. I have already on a previous occasion sent the information to a spreadsheet and I still have the code, 'commented out' in my program.

User avatar
dasmanul
Posts: 502
Joined: Wed Sep 30, 2015 10:20 am
Location: Frankfurt, Germany

Re: Open another window and switch between?

Wed Jun 29, 2016 4:17 pm

FYI, since you mentioned similarities to my project: I've since described it in some more detail here on the forum, thought maybe you'd want to have a look.

RDS
Posts: 721
Joined: Tue Oct 06, 2015 8:17 am
Location: Lancashire, UK

Re: Open another window and switch between?

Wed Jun 29, 2016 6:03 pm

@dasmanul
That is very interesting and I have tagged the thread to keep an eye on it and refer back.
Thank you very much for this and your help today on the other thread.

Return to “Python”