1 / 8

Graphical User Interfaces

Graphical User Interfaces. Making the thing look classy!!. Learning Objectives. Understand the need for a GUI Know how to design a GUI Understand how to code a GUI in Python. Why do we need a GUI. The other option is Command Line or punch cards!!!. Nice and Easy to use.

Download Presentation

Graphical User Interfaces

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Graphical User Interfaces Making the thing look classy!!

  2. Learning Objectives • Understand the need for a GUI • Know how to design a GUI • Understand how to code a GUI in Python

  3. Why do we need a GUI • The other option is Command Line or punch cards!!! Nice and Easy to use Annoying and a waste of time Slightly more difficult to use

  4. How does a GUI work in Python Its all about layers and grids Widgets Username Submit Window Frame

  5. Sample Code from tkinter import * root = Tk() root.title("Test") root.geometry("300x300”) root.mainloop() Import the GUI library Create an instance of a window Assign a title to the window Create the size of the window Make the window show The output from the code above

  6. Adding some text to the GUI from tkinter import * root = Tk() root.title("Test") root.geometry("300x300") label = Label(root,text="Username") label.pack() root.mainloop() In python to add text you need to use the Label. The label then needs to be added to the window using pack Output from the code

  7. Adding a button to the GUI from tkinter import * defaddText(): label1 = Label(root, text="You've clicked the button") label1.pack() root = Tk() root.title("Test") root.geometry("300x300") label = Label(root,text="Username") label.pack() btn = Button(root, text="Click Me", command=addText) btn.pack() root.mainloop() In python to add text you need to use the Button. Once again the button is then added to the window using pack To get the button to do something you have to use the command parameter Output from the code Before Click After Click

  8. Adding a text box to the GUI from tkinter import * root = Tk() root.title("Test") root.geometry("300x300") label = Label(root,text="Username") label.pack() txt = Entry(root, bd=1) txt.pack() btn = Button(root, text="Click Me") btn.pack() root.mainloop() In python to add text you need to use the Entry. Once again the button is then added to the window using pack Output from the code

More Related