Difference between revisions of "Using Tkinter and Other Graphical Applications on Bowie"

From Earlham CS Department
Jump to navigation Jump to search
(Created page with "= <span style="color:red"> Please Disregard Information on this Page, it is still under construction and will be completed soon!!!!</span> = When Running Tkinter on Bowie th...")
 
m
 
(12 intermediate revisions by one other user not shown)
Line 1: Line 1:
= <span style="color:red"> Please Disregard Information on this Page, it is still under construction and will be completed soon!!!!</span> =
 
  
 +
= Overview =
 +
When attempting to run graphical application software on a remote connection i.e. our servers, via an SSH connection one must use the -Y optional. This allows for the use of X11 forwarding, in which is a networking protocol that allows you to launch the display that will be produced by the graphical application on your screen, allowing you to interact with the graphical interface. Without this, you will get an error when running on the CS servers indicating that the application has no screen to forward the display to. Please visit [https://www.emtec.com/ssh/x11-forwarding.html here] for more information on X11 forwarding.
 +
<br />Below is an example, of how to use Tkinter, a python GUI package on both the servers and your own machine. Although the steps may vary for your specific application the initial first few steps will still apply when attempting to run any graphical application on the servers. 
  
When Running Tkinter on Bowie there are some steps one must complete before using the Package.
+
= Tkinter for Mac Users =
 +
 
 +
== CS Servers  ==
  
= Tkinter for Mac Users =
+
#Mac requires the use of Xquartz an X server program that manages the graphical connection between you and the remote client. Ensure Xquartz is installed on your machine and open the Xquartz terminal, you will run all the following commands here.To install Xquartz on your machine you may look at the [https://www.xquartz.org/ Xquarts website].
 +
#Open the Tkinter terminal and type: xhost + (this relaxes the security of your system and ready it for X11 forwarding).
 +
#SSH onto Bowie(tools) with the -Y option (this will  establish the X11 connection): ssh -Y <username>@bowie.cs.earlham.edu.
 +
#Load a python environment, preferably one that is a newer version of python. It is not promised that Tkinter will work for versions below 2.7: module load python/3.9
 +
#Create your python script. <span style="color:red">Do not name your script "tkinter.py".<span>
 +
#At the top of the script type <code> from Tkinter import *</code>.
  
Tkinter is an X11 application thus one must:
+
Below is some test code to ensure everything is working. Create a python file in your terminal type in the script:
== CS Servers ==
+
    from tkinter import *  
*Ensure Xquartz is installed on your machine and open the Xquartz terminal you will run all the following commands here.
+
    window = Tk()
*Open the Tkinter terminal and type: xhost + (this relaxed the security of your system and opens it up for X11 forwarding)
+
    window.title("Welcome to My Tkinter app")
*SSH onto Bowie(tools) with the -Y option (this will allow for X11 Forwarding): ssh -Y <username>@bowie.cs.earlham.edu
+
    lbl = Label(window, text="Hello")
*Load a python environment, preferably one that is a newer version of python. It is not promised that tkinter will work for versions below 2.7: module load python/3.9
+
    lbl.grid(column=0, row=0)
*Create your python script do not name your script "tkinter.py"
+
    window.mainloop()
*At the top of the script type from Tkinter import *
 
  
Below is some test code to ensure everything is working. Create a python file in your terminal type in the script and run it: <code>python3 <file name><code>  
+
Run the script using <code>python3 <file-name></code>. A small window should appear on your screen named "Welcome to My Tkinter app" with the text "Hello" written inside the window.
<code>
 
from tkinter import * <br />
 
window = Tk() <br />
 
window.title("Welcome to My Tkinter app") <br />
 
lbl = Label(window, text="Hello") <br />
 
lbl.grid(column=0, row=0) <br />
 
window.mainloop() <br />
 
<code>
 
  
 
== Personal Machine ==
 
== Personal Machine ==
*Load a python environment, preferably one that is a newer version of python. It is not promised that tkinter will work for versions below 2.7: module load python/3.9
+
For your personal machine:
*Create your python script do not name your script "tkinter.py"
+
#As in the previous section ensure Xquartz is installed on your machine.
*At the top of the script type from Tkinter import *
+
#Ensure that python 2.7 or higher is installed on your machine.It is not promised that tkinter will work for versions below 2.7.
 +
#Create your python script. <span style="color:red">Do not name your script "tkinter.py"<span>
 +
#At the top of the script type <code>from Tkinter import *</code>
  
 +
You can run the same test code as stated above.
  
A small window should appear on your computer named "Welcome to My Tkinter app" with the text "Hello" written inside the window.
+
= Tkinter for Windows Users =
  
 +
==CS Servers==
  
= Tkinter for Windows Users =
+
No other application for Windows is needed you can run the commands below as-is:
==CS Servers==
 
No other application for Windows is needed you can run the commands below as is:
 
  
* In your Ubuntu terminal SSH onto Bowie(tools) with the -Y option: ssh -Y <username>@bowie.cs.earlham.edu
+
# In your Ubuntu terminal SSH onto bowie(tools) with the -Y option:<code> ssh -Y <username>@bowie.cs.earlham.edu </code>
*Load a python environment, preferably one that is a newer version of python it is not promised that tkinter will work for versions below 2.7: module load python/3.9
+
#Load a python environment, preferably one that is a newer version of python it is not promised that tkinter will work for versions below 2.7: <code>module load python/3.9</code>
*Create your python script do not name your script "tkinter.py"
+
#Create your python script do not name your script "tkinter.py"
*At the top of the script type from tkinter import *
+
#At the top of the script type from tkinter import *
  
Below is some test code to ensure everything is working. Create a python file in your terminal type in the script and run it: <code>python3 <file name><code>
+
Below is some test code to ensure everything is working. Create a python file in your terminal type in the script and run it: <code>python3 <file name></code>
  
<code>
+
  from tkinter import *
<br /> from tkinter import * <br />
+
  window = Tk()  
window = Tk() <br />
+
  window.title("Welcome to My Tkinter app")
window.title("Welcome to My Tkinter app") <br />
+
  lbl = Label(window, text="Hello")
lbl = Label(window, text="Hello") <br />
+
  lbl.grid(column=0, row=0)
lbl.grid(column=0, row=0) <br />
+
  window.mainloop()
window.mainloop() <br />
 
<code>
 
  
A small window should appear on your computer named "Welcome to My Tkinter app" with the text "Hello" written inside the window.
+
A small window should appear on your screen named "Welcome to My Tkinter app" with the text "Hello" written inside the window.
  
 
== Personal Machine ==
 
== Personal Machine ==
*Load a python environment, preferably one that is a newer version of python. It is not promised that tkinter will work for versions below 2.7: module load python/3.9
+
#Load a python environment, preferably one that is a newer version of python. It is not promised that tkinter will work for versions below 2.7.
*Create your python script do not name your script "tkinter.py"
+
#Create your python script do not name your script "tkinter.py"
*At the top of the script type from Tkinter import *
+
#At the top of the script type <code> from Tkinter import *</code>.
 +
You can run the same test code as stated above.
 +
 
 +
= Other Graphical Applications installed on the Servers =
 +
Along with tkinter, pygame is also installed on the CS servers. Despite what graphical application you use the general first 3 steps explained in the "Tkinter for Mac Users" section must be applied for MacOS machines and the first step in the "Tkinter for Windows Users" will apply for those using Windows.
 +
 
 +
Please contact the admins if any problem should arise when going through the steps above or for the installation of graphical application software on the CS servers.
  
= Issues =
+
Tested and working 2022
If you have any questions or issues feel free to contact the admins.
 

Latest revision as of 13:42, 26 November 2022

Overview

When attempting to run graphical application software on a remote connection i.e. our servers, via an SSH connection one must use the -Y optional. This allows for the use of X11 forwarding, in which is a networking protocol that allows you to launch the display that will be produced by the graphical application on your screen, allowing you to interact with the graphical interface. Without this, you will get an error when running on the CS servers indicating that the application has no screen to forward the display to. Please visit here for more information on X11 forwarding.
Below is an example, of how to use Tkinter, a python GUI package on both the servers and your own machine. Although the steps may vary for your specific application the initial first few steps will still apply when attempting to run any graphical application on the servers.

Tkinter for Mac Users

CS Servers

  1. Mac requires the use of Xquartz an X server program that manages the graphical connection between you and the remote client. Ensure Xquartz is installed on your machine and open the Xquartz terminal, you will run all the following commands here.To install Xquartz on your machine you may look at the Xquarts website.
  2. Open the Tkinter terminal and type: xhost + (this relaxes the security of your system and ready it for X11 forwarding).
  3. SSH onto Bowie(tools) with the -Y option (this will establish the X11 connection): ssh -Y <username>@bowie.cs.earlham.edu.
  4. Load a python environment, preferably one that is a newer version of python. It is not promised that Tkinter will work for versions below 2.7: module load python/3.9
  5. Create your python script. Do not name your script "tkinter.py".
  6. At the top of the script type from Tkinter import *.

Below is some test code to ensure everything is working. Create a python file in your terminal type in the script:

   from tkinter import * 
   window = Tk()
   window.title("Welcome to My Tkinter app")
   lbl = Label(window, text="Hello")
   lbl.grid(column=0, row=0)
   window.mainloop()

Run the script using python3 <file-name>. A small window should appear on your screen named "Welcome to My Tkinter app" with the text "Hello" written inside the window.

Personal Machine

For your personal machine:

  1. As in the previous section ensure Xquartz is installed on your machine.
  2. Ensure that python 2.7 or higher is installed on your machine.It is not promised that tkinter will work for versions below 2.7.
  3. Create your python script. Do not name your script "tkinter.py"
  4. At the top of the script type from Tkinter import *

You can run the same test code as stated above.

Tkinter for Windows Users

CS Servers

No other application for Windows is needed you can run the commands below as-is:

  1. In your Ubuntu terminal SSH onto bowie(tools) with the -Y option: ssh -Y <username>@bowie.cs.earlham.edu
  2. Load a python environment, preferably one that is a newer version of python it is not promised that tkinter will work for versions below 2.7: module load python/3.9
  3. Create your python script do not name your script "tkinter.py"
  4. At the top of the script type from tkinter import *

Below is some test code to ensure everything is working. Create a python file in your terminal type in the script and run it: python3 <file name>

  from tkinter import *
  window = Tk() 
  window.title("Welcome to My Tkinter app")
  lbl = Label(window, text="Hello")
  lbl.grid(column=0, row=0)
  window.mainloop()

A small window should appear on your screen named "Welcome to My Tkinter app" with the text "Hello" written inside the window.

Personal Machine

  1. Load a python environment, preferably one that is a newer version of python. It is not promised that tkinter will work for versions below 2.7.
  2. Create your python script do not name your script "tkinter.py"
  3. At the top of the script type from Tkinter import *.

You can run the same test code as stated above.

Other Graphical Applications installed on the Servers

Along with tkinter, pygame is also installed on the CS servers. Despite what graphical application you use the general first 3 steps explained in the "Tkinter for Mac Users" section must be applied for MacOS machines and the first step in the "Tkinter for Windows Users" will apply for those using Windows.

Please contact the admins if any problem should arise when going through the steps above or for the installation of graphical application software on the CS servers.

Tested and working 2022