top of page

If you don't have Eclipse Luna R installed with PyDev please refer to the CRYOGEN tab and click PyDev. We will be starting with a GUI.

 

Please click on the "Python Tab" text: "PYTHON" to get the hidden tab.

Once you have PyDev and Eclipse Luna R installed, please copy paste this exactly how it is into a new project, new file with a .py extention like "window.py". I won't have time until next weekend to go through with all the meanings of everything but this should show a window, with a button and a statement. We will be exploring all possibilities of making a Window GUI configured to anything you'd like to have on it. Click Run, and the window will appear, click the "x" to exit. This portion of the code isn't really correct. Unless you just want two windows and buttons that are themed through "ttk". Read after and try this code. Same idea, but with a password.

 

from tkinter import ttk
import tkinter
import tempfile

ICON = (b'\x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x08\x00h\x05\x00\x00'
    b'\x16\x00\x00\x00(\x00\x00\x00\x10\x00\x00\x00 \x00\x00\x00\x01\x00'
    b'\x08\x00\x00\x00\x00\x00@\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
    b'\x00\x01\x00\x00\x00\x01') + b'\x00'*1282 + b'\xff'*64

_, ICON_PATH = tempfile.mkstemp()
with open(ICON_PATH, 'wb') as icon_file:
    icon_file.write(ICON)

 

root = tkinter.Tk()
root.title("EKX Development")
root.iconbitmap(default = ICON_PATH)

root.geometry("700x300")
label = tkinter.Label(root, text = "Welcome to EKX Development.")
label.pack()


style = ttk.Style()
style.layout("TMenubutton", [
   ("Menubutton.background", None),
   ("Menubutton.button", {"children":
       [("Menubutton.focus", {"children":
           [("Menubutton.padding", {"children":
               [("Menubutton.label", {"side": "left", "expand": 1})]
           })]
       })]
   }),
])

mbtn = ttk.Menubutton(text = 'Are you an EKX?')
mbtn.pack()

root.mainloop()

 

# this is a comment

""" This is a longer comment that also will not show up in the running program """

 

import tkinter
import tempfile

ICON = (b'\x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x08\x00h\x05\x00\x00'
    b'\x16\x00\x00\x00(\x00\x00\x00\x10\x00\x00\x00 \x00\x00\x00\x01\x00'
    b'\x08\x00\x00\x00\x00\x00@\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
    b'\x00\x01\x00\x00\x00\x01') + b'\x00'*1282 + b'\xff'*64

_, ICON_PATH = tempfile.mkstemp()
with open(ICON_PATH, 'wb') as icon_file:
    icon_file.write(ICON)
    
class Application(tkinter.Frame):

 

    """ You have to add tkinter.[Frame, Label, Button as tkinter.Button or tkinter.x where x is the name that needs to be adjusted. For instance if I used the regular tkinter, I would have the logo and "Tk" in the window, but this way I have no logo of Tkinter and Tk but have to add tkinter. to anything that will be used graphically. """

 

    def __init__(self, master):
        """ This initializes the Frame"""
        tkinter.Frame.__init__(self, master)
        self.grid()
        self.create_widgets()
    
    def create_widgets(self):
        """ . """
        self.instruction = tkinter.Label(self, text = "Enter the Password")
        self.instruction.grid(row = 0, column = 0, columnspan = 2, sticky = tkinter.W) #tkinter.W is of 'north, south, east, west on the grid'
        
        self.password = tkinter.Entry(self)
        self.password.grid(row = 1, column = 1, sticky = tkinter.W)
        
        self.submit_button = tkinter.Button(self, text = "Submit", command = self.reveal)
        self.submit_button.grid(row = 2, column = 0, sticky = tkinter.W)
        
        self.text = tkinter.Text(self, width = 35, height = 5, wrap = tkinter.WORD)

 

"""we use WORD, because it's more than a character and is a string longer than a normal exception like 'a', 'b' or 'c' in return."""


        self.text.grid(row = 3, column = 0, columnspan = 2, sticky = tkinter.W)
        
    def reveal(self):
        """ Display MESSAGE """
        content = self.password.get()
        
        if content == "password": # If you type in password into the box, you will receive the below text output.
            message = "You have access to something special."
        else:
            message = "Access denied."
        self.text.delete(0.0, tkinter.END)
        self.text.insert(0.0, message)

root = tkinter.Tk()
root.title("Password Accept")
root.geometry("500x300")
app = Application(root)

 

"" This is an excess window I'm working on, all I needed to do was write the below to make a new window withh the same template with no logo """


root.title("rename")

wnewwindow = tkinter.Toplevel(root)
wnewwindow.title("rename1")
wnewwindow.iconbitmap(default=ICON_PATH)


label = tkinter.Label(wnewwindow, text="Window with transparent icon.")
label.pack()

root.mainloop() # we end with .mainloop(), sometimes root will not always be the exiting loop.

 

""" This is the original code with the Tk logo in the header. Notice I didn't need to use tkinter. over and over."""

 

from tkinter import *

class Application(Frame):
    """ A GUI application with three buttons."""
    def __init__(self, master):
        """ This initializes the Frame"""
        Frame.__init__(self, master)
        self.grid()
        self.create_widgets()
    
    def create_widgets(self):
        """Create 3 buttons that do nothing."""
        #create first button
        self.button1 = Button(self, text = "Press me.")
        self.button.grid()
        
        #create second button
        self.button2 = Button(self)
        self.button2.grid
        self.button2.configure(text = "This is text")
        
        #create 3rd button
        self.button3 = Button(self)
        self.button3.grid()
        self.button3["text"] = "This is secondary text"
        
root = Tk()
root.title("Lazy Buttons")
root.geometry("200x85")

app = Application(root)

root.mainloop()

bottom of page