1 / 48

Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Python Training | Edureka

( ** Python Certification Training: https://www.edureka.co/python ** ) <br>This Edureka PPT on Tkinter tutorial covers all the basic aspects of creating and making use of your own simple Graphical User Interface (GUI) using Python. It establishes all of the concepts needed to get started with building your own user interfaces while coding in Python.

EdurekaIN
Download Presentation

Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Python Training | Edureka

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. Tkinter Agenda Python Certification Training https://www.edureka.co/python

  2. Tkinter Agenda Python Certification Training https://www.edureka.co/python

  3. Agenda 01 Introduction Introduction to Flask 02 Getting Started Installing and working with Flask 03 Concepts Overview of all the concepts in Flask 04 Practical Approach Looking at code to understand theory Python Certification Training https://www.edureka.co/python

  4. Tkinter What Is A Graphical User Interface? Python Certification Training https://www.edureka.co/python

  5. What Is A GUI? GUIis a desktop app which helps you to interact with computers What is GUI? GUI Apps Text Editors Games I’ll learn Tkinter! Python Certification Training https://www.edureka.co/python

  6. Why We Need GUI? Command Line Graphical User Interface The graphical user interface, is a type of user interface that allows users to interact with electronic devices through graphical icons and visual indicators Python Certification Training https://www.edureka.co/python

  7. Tkinter Python Libraries For GUI Python Certification Training https://www.edureka.co/python

  8. Why We Need GUI? Life without Tkinter! Using Tkinter! Python Certification Training https://www.edureka.co/python

  9. Tkinter What Is Tkinter? Python Certification Training https://www.edureka.co/python

  10. Introduction to Flask Tkinterin Python GUI Programming is standard Python GUI library It gives us an object-oriented interface to the Tk GUI toolkit Python Certification Training https://www.edureka.co/python

  11. Tkinter Fundamentals Of Tkinter Python Certification Training https://www.edureka.co/python

  12. First Window Using Tkinter Import the Tkintermodule Create the GUI application main window Enter the main event loop Add Widgets import tkinter window = tkinter.Tk() # to rename the title of the window window.title("GUI") # pack is used to show the object in the window label = tkinter.Label(window, text = "Hello World!").pack() window.mainloop() Python Certification Training https://www.edureka.co/python

  13. Tkinter Tkinter Widgets Python Certification Training https://www.edureka.co/python

  14. Adding Widgets To Our Application A widget is an element of a graphical user interface (GUI) that displays information or provides a specific way for a user to interact with theoperating systemor anapplication Label Button Entry ComboBox CheckButton Radio ScrolledText SpinBox Menu Bar Notebook Python Certification Training https://www.edureka.co/python

  15. Label Widget Label You can set the label font so you can make it bigger and maybe bold Output: Example: l1 = Label (window, text="edureka!“ font=("Arial Bold", 50)) l1.grid (column=0, row=0) Changing the font style and size Python Certification Training https://www.edureka.co/python

  16. Label Widget Label We can set the default window size using geometry function Output: Example: l1 = Label (window, text="edureka!“ font=("Arial Bold", 50)) window.geometry('350x200') l1.grid (column=0, row=0) The above line sets the window width to 350 pixels and the height to 200 pixels Python Certification Training https://www.edureka.co/python

  17. Button Widget Let’s start by adding the button to the window, the button is created and added to the window the same as the label Button Output: Example: bt = Button (window, text="Enter") bt.grid (column=1, row=0) Using grid function to set the button position Python Certification Training https://www.edureka.co/python

  18. Button Widget • You can change foreground for a button or any other widget usingfgproperty. • Also, you can change the background color for any widget usingbgproperty. Button Output: Example: bt = Button (window, text="Enter", bg="orange", fg="red") bt.grid (column=1, row=0) Changing the background and foreground color Python Certification Training https://www.edureka.co/python

  19. Button Widget • Let’s add button click event • First, we will write the function that we need to execute when the button is clicked Button Example: def clicked(): Function that will execute the button click event l1.configure (text="Button was clicked !!") bt = Button (window, text=“Enter”, command=clicked) Wiring the button with the function Python Certification Training https://www.edureka.co/python

  20. Entry Widget In the previous Python GUI examples, we saw how to add simple widgets. Now let’s try getting the user input using TkinterEntry class (Tkintertextbox) Entry Example: txt = Entry(window,width=10) Creating a textbox using TkinterEntry class txt.grid(column=1, row=0) def clicked(): Once the button is clicked show “Welcome to” concatenated with the entered text res = "Welcome to " + txt.get() l1.configure(text= res) bt = Button (window, text=“Enter”, command=clicked) Python Certification Training https://www.edureka.co/python

  21. Entry Widget Entry Python Certification Training https://www.edureka.co/python

  22. Combobox Widget Combobox ComboboxWidgets are very easy to use and are widely used as well! Example: from tkinter.ttk import * Adding the comboboxitems using the tuple combo = Combobox(window) combo['values']= (1, 2, 3, 4, 5, "Text") combo.current(3) Setting the selected item combo.grid(column=0, row=0) Python Certification Training https://www.edureka.co/python

  23. Combobox Widget Python Certification Training https://www.edureka.co/python

  24. Checkbutton Widget Checkbutton To create a checkbuttonwidget, you can use Checkbuttonclass Example: chk_state = BooleanVar() Creating a variable of type BooleanVarwhich is not a standard Python variable, it’s a Tkintervariable chk_state.set (True) chk = Checkbutton(window, text=‘Select', var=chk_state) chk.grid(column=0, row=0) Passing the chk_stateto the Checkbutton class to set the check state Python Certification Training https://www.edureka.co/python

  25. Checkbutton Widget Checkbutton Python Certification Training https://www.edureka.co/python

  26. Radio Button Widget To add radio buttons, simply you can use RadioButtonclass Radio Button Example: rad1 = Radiobutton(window, text=Python', value=1) You should set the value for every radio button with a different value, otherwise, they won’t work rad2 = Radiobutton(window, text=Java', value=2) rad3 = Radiobutton(window, text=Scala', value=3) rad1.grid(column=0, row=0) rad2.grid(column=1, row=0) rad3.grid(column=2, row=0) Python Certification Training https://www.edureka.co/python

  27. Radio Button Widget Radio Button Python Certification Training https://www.edureka.co/python

  28. ScrolledText Widget To add a ScrolledTextwidget, you can use the ScrolledTextclass ScrolledText Example: from tkinter import scrolledtext txt = scrolledtext.ScrolledText(window, width=40,height=10) Here we specify the width and the height of the ScrolledTextwidget, otherwise, it will fill the entire window To set scrolledtextcontent, you can use the insert method -txt.insert(INSERT,'Youtext goes here') Python Certification Training https://www.edureka.co/python

  29. MessageBox Widget To show a message box using Tkinter, you can use messageboxlibrary MessageBox Example: Example: def clicked(): from tkinter import messagebox messagebox.showinfo('Message title', 'Message content') messagebox.showinfo('Message title’, 'Message content') btn = Button(window,text=‘ENTER', command=clicked) Shows a message box when the user clicks a button Python Certification Training https://www.edureka.co/python

  30. MessageBox Widget MessageBox Python Certification Training https://www.edureka.co/python

  31. SpinBox Widget To create a Spinboxwidget, you can use the Spinboxclass SpinBox Example: Output: spin = Spinbox(window, from_=0, to=100, width=5) Python Certification Training https://www.edureka.co/python

  32. Tkinter Geometry Management Python Certification Training https://www.edureka.co/python

  33. Geometry Management All tkinterwidgets will have geometric measurements Geometry Manager Classes pack() grid() place() It organizes the widgets in the block, which mean it occupies the entire available width It organizes the widgets in table-like structure It's used to place the widgets at a specific position you want. Python Certification Training https://www.edureka.co/python

  34. Tkinter Organizing Layout & Widgets Python Certification Training https://www.edureka.co/python

  35. Organizing Layout And Widgets We use Frame class to arrange layout in a window Frame is used to create the divisions in the window. You can align the frames as you like with side parameter of pack() method. Frame Button is used to create a button in the window. It takes several parameters like text(Value of the Button), fg(Colorof the text), bg(Background color) Button Let’s see some code Python Certification Training https://www.edureka.co/python

  36. Organizing Layout And Widgets Sample Login Box Grid is another way to organize the widgets. It uses the Matrix row column concepts. Grid Let’s see more code Python Certification Training https://www.edureka.co/python

  37. Tkinter Binding Functions Python Certification Training https://www.edureka.co/python

  38. Binding Functions Calling functions whenever an event occurs refers to a binding function. Binding import tkinter window = tkinter.Tk() window.title("GUI") # creating a function called say_hi() def say_hi(): tkinter.Label(window, text = "Hi").pack() tkinter.Button(window, text = "Click Me!", command = say_hi).pack() window.mainloop() I like code! Python Certification Training https://www.edureka.co/python

  39. Tkinter Event Handling Python Certification Training https://www.edureka.co/python

  40. Event Handling mousemove, mouseover, clicking, scrolling are some events Events Mouse Buttons <Button-1> <Button-2> <Button-3> Left Click Middle Click Right Click Python Certification Training https://www.edureka.co/python

  41. Tkinter Images & Icons Python Certification Training https://www.edureka.co/python

  42. Images & Icons Images can be added using the PhotoImagemethod Add Images We love Edureka <3 Python Certification Training https://www.edureka.co/python

  43. Tkinter Use Case Python Certification Training https://www.edureka.co/python

  44. Use Case – Simple Calculator Let us design our own basic calculator using tkinter Python Certification Training https://www.edureka.co/python

  45. Tkinter Conclusion Python Certification Training https://www.edureka.co/python

  46. Conclusion I learnt Tkinter, yay! Python Certification Training https://www.edureka.co/python

More Related