Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work in WSL because tkinter is required #5

Open
nmk456 opened this issue Jan 23, 2021 · 20 comments
Open

Doesn't work in WSL because tkinter is required #5

nmk456 opened this issue Jan 23, 2021 · 20 comments

Comments

@nmk456
Copy link

nmk456 commented Jan 23, 2021

Running pico_project.py in WSL fails because there's no GUI and therefore no tkinter module. This could be fixed perhaps by only importing tkinter if pico_project.py is run with the GUI option.

@JamesH65
Copy link
Contributor

Interesting. I didn't try WSL, just Linux (x86 and Arm), Windows and Mac. I know nothing of WSL, but presumably installing tkinter library is not a possibility if there is no GUI. Will have a think.

@SuperNinja-4965
Copy link
Contributor

WSL does not support GUI's at all yet. Microsoft plan to add this feature in the future. If you are going to want to use a GUI then you are going to need to run it on windows itself by installing python.

@JamesH65
Copy link
Contributor

Had a quick investigate, and can conditionally import, so will sort that out on Monday.

@SuperNinja-4965
Copy link
Contributor

SuperNinja-4965 commented Jan 23, 2021

After a quick google i was able to find out that you can install tkinter using: sudo apt-get install python3-tk.
I was able to install that on my version of windows subsystem for linux (Ubuntu) and i was able to get the script to run with no modifications.
I have not done much testing so i cannot say for sure if this works 100%.
I will report back when i have done some more testing

@SuperNinja-4965
Copy link
Contributor

Ok so far I have had no issues after insalling the module. Looks like that has appeared to fix the issue @nmk456 .

@JamesH65
Copy link
Contributor

I'll still fix it up, shouldn't need tkinter installed if only running from the command line.

@JamesH65
Copy link
Contributor

Hmm, bit more of a PITA that initially thought. Without TKInter a load of top level classes break the rest of the code as tk is undefined. Will need to swot up a bit more on Python and imports etc.

@SuperNinja-4965
Copy link
Contributor

am i correct in thinking tkinter is only needed for loading the gui?

@SuperNinja-4965
Copy link
Contributor

If so then can you just use an if statement to import the tkinter module only when the gui option is called?

@SuperNinja-4965
Copy link
Contributor

SuperNinja-4965 commented Jan 25, 2021

Ok this is a bit messy and definatly is not the neatest solution. but i have thrown together a "patch" based on my comment/thought before that basically only imports and runs code that needs tkinter when the --gui or -g option is called.
I have not done massive amounts of testing but it does appear to work.
I did have to reshuffle some lines of code but nothing has been removed.
I hope this is a little help to build a neater solution. There is a chance i broke something but i have not spotted any bugs atm.
I have attached a zip of these modifications of this project with the possible patch.

SHA-256: E6F5CD91BD23A4895175F5BDEEDD540B2075C339C32B8E64CC7EC4C646C78780
pico-project-generator-MODIFIED.zip
VirusTotal of the file for security: https://www.virustotal.com/gui/file-analysis/Mzk1NDk3OGQxNmEzMzIzMmZlMzA5M2Y1ZDA2MGU4NjA6MTYxMTU5MTQxOQ==/detection

I hope this is somewhat useful!

EDIT: Oh btw i tested this on windows (normal python install with tkinter) and WSL with the tkinter module uninstalled.

@JamesH65
Copy link
Contributor

I was trying something along those lines. The mass movement of classes is a PITA. Will do something similar and try and maintain some semblance of code sanity!

@JamesH65
Copy link
Contributor

Note, also need to surround the TK import in try catch because you still need to catch people asking for a GUI when its not supported.

@SuperNinja-4965
Copy link
Contributor

Ok so I have done a massive restructure of the code... It took a while. Nothing has changed only how the code is stored and how different things are called. The restructure allows for the program to work fine without tkinter without a GUI.
The restructure also allows possible easier expansion of the code. The restructure splits the code into 4 python files:
pico_project.py - This is the start file (Like normal) this is where the program enters and receives any parameters.
pico_project_generation.py - This file was needed when ripped the GUI from the main file to prevent import loops and incomplete import errors.
pico_project_settings.py - in here are all the variables that are needed by all of the other files in the project. I also put things like the code fragments and lists to make them easy to find when adding more. Again, this was needed so the main 2 files pico_project and pico_project_gui can access all the variables needed.
pico_project_gui.py - This contains ALL code needed for the gui. If the user wanted to they could drop this file entirely and the project would/should work fine without a GUI.
If you decide to merge this code, I would highly recommend testing my code and double checking it before merging it with the master.
The code also is not the neatest, but I have tried my best!
I really hope this helps at least a little!
I have created a pull request with the code so you can easily see it.
Once again i have done some testing on both windows (normal python install with tkinter) and WSL with the tkinter module uninstalled.
Pull request: #11

@SuperNinja-4965
Copy link
Contributor

Note, also need to surround the TK import in try catch because you still need to catch people asking for a GUI when its not supported.

Oh while i remember i forgot to add this into my code. but it shouldn't matter too much because if they are trying to run a gui in an environment that does not have one installed or supported then that will be the only time the program crashes.

@JamesH65
Copy link
Contributor

I'll take a look as son as I can, I suspect a change this large will need a loot of checking over, but its along the lines I was thinking of, so useful. Not how how splitting it up will affects its running in all circumstances.

@SuperNinja-4965
Copy link
Contributor

Oh yeah i agree a change that massive will needs lots of looking over! It wont necessarily affect the running in most circumstances but it will make the code easier to maintain and having the settings inside one file makes changing them a little easier.

@sharma-kullu2
Copy link

Just so most of us are going to use WSL for development, I would like to add my contribution in closing this issue.

  1. tkinter can be installed using following apt repo and hence the python code will execute generator well in terminal.
    $sudo apt-get install python3-tk
  2. In order to run the GUI we can leverage the X11 server running on windows host using vcxsrv.exe (which I am using) and set the remote client as your distro running in WSL, here is a great article.
    https://medium.com/javarevisited/using-wsl-2-with-x-server-linux-on-windows-a372263533c3
  3. In order to launch the UI, set up X11 server as described in the article. To run the generator add following script, which is very basic and serves the purpose. Copy the script to the root directory of the project-generator folder.
    gui.txt

@lurch
Copy link
Contributor

lurch commented May 8, 2021

Just so most of us are going to use WSL for development

I don't know where you got that idea? We (Raspberry Pi) don't provide any instructions for Pico development using WSL, and therefore we don't officially support it. But if you want to use it, and it works for you, then great 👍 🙂

@berrak
Copy link
Contributor

berrak commented Jul 12, 2021

Looks that the tkintermodule installation itself, or rather the documentation for the installation on Linux based platforms (Ubuntu/Debian/RPI) has cause some unnecessary issues over time.
I submitted a simple PR for the README which fix that issue.

@mklemarczyk
Copy link

Could the library tkinter be loaded only in GUI mode? It does not bring any value in CLI mode.
Python is dynamic in the library loading, we could define that GUI parts are not loaded in CLI mode of script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants