Tk button with onClick event To create a Tkinter window with a button use the example below. The program enters mainloop() which wait for events (user actions). We define the button which has a callback to the function callback(). master is the root window, the window where your button will appear in.
tk button Tk image button If you want an image button, use the PhotoImage class. We set the size of the window and the miminum size with the functions minsize() and geometry(). Example:
Result: tk button with text and imageButton location If you want to place the button on your coordinates do not use the pack() function but instead use the function place(x,y), as shown in the example below:
The Tkinter toolkit comes with all the basic widgets to create graphical applications. Almost every app has a main menu. As expected, Tkinter supports adding a main menu to your application window.
The screenshot below demonstrates a Tkinter based menu:
Tkinter menu
You can create a simle menu with Tkinter using the code below. Every option (new, open, save.. ) should have its own callback.
where root is a Tk() object.
A menubar may contain zero or more submenus such as the file menu, edit menu, view menu, tools menu etcetera.
A submenu can be created using the same Menu() call, where the first argument is the menubar to attach to.
filemenu = Menu(menubar, tearoff=0)
menu = Menu(menubar, tearoff=0)
Individual options can be added to these submenus using the add_command() method:
In the example we created the callback function donothing() and linked every command to it for simplicity. An option is added using the add_comment() function. We call add_cascade() to add this menu list to the specific list.
TKINTER WIDGETS
Tk widgets
Tkinter has several widgets including:
Label
EditText
Images
Buttons (Discussed before)
In this article we will show how to use some of these Tkinter widgets. Keep in mind there’s a slight difference between Tkinter for Python 2.x and 3.x
Label To create a label we simply call the Label() class and pack it. The numbers padx and pady are the horizontal and vertical padding.
The Tkinter tkMessageBox has various methods to display a message box.
There is a slight difference between Tkinter for Python 2.7 and Python 3. To find your Python version try one of these commands:
TkMessage boxTo show a minimalistic Tkintermessage box, use the function showinfo() where the parameters are the window title and text.
The showinfo() function is in a different module depending on the Python version. Python 3.x
from tkinter import messagebox
messagebox.showinfo("Title","a Tk MessageBox")
importTkinterimport tkMessageBox
# An error box
tkMessageBox.showerror("Error","No disk space left on device")# A warning box
tkMessageBox.showwarning("Warning","Could not start service")# An information box
tkMessageBox.showinfo("Information","Created in Python.")
TKFILE DIALOGUE MODULE IN TKINTER
tkFileDialog is a module with open and save dialog functions.
Instead of implementing those in Tkinter GUI on your own
Overview An overview of file dialogs:
Function
Parameters
Purpose
.askopenfile
Directory, Title, Extension
To open file: Dialog that requests selection of an existing file.
.asksaveasfilename
Directory, Title, Extension)
To save file: Dialog that requests creation or replacement of a file.
.askdirectory
None
To open directory
Tkinter Open File
The askopenfile function to creates an file dialog object. The extensions are shown in the bottom of the form (Files of type). The code below will simply show the dialog and return the filename. If a user presses cancel the filename is empty. On a Windows machine change the initialdir to “C:\”. Python 2.7 version:
Tkinter supports dropdown menus. This is similar to your standard combobox on your operating system.
The widget is called OptionMenu and the parameters you need are: frame, tk variable and a dictionary with choices.
Tkinter dropdown example
The example below creates a Tkinter window with a combobox.
fromTkinterimport *
importTkinteras ttk
from ttk import *
root = Tk()
root.title("Tk dropdown example")# Add a grid
mainframe = Frame(root)
mainframe.grid(column=0,row=0, sticky=(N,W,E,S))
mainframe.columnconfigure(0, weight =1)
mainframe.rowconfigure(0, weight =1)
mainframe.pack(pady =100, padx =100)# Create a Tkinter variable
tkvar = StringVar(root)# Dictionary with options
choices ={'Pizza','Lasagne','Fries','Fish','Potatoe'}
tkvar.set('Pizza')# set the default option
popupMenu = OptionMenu(mainframe, tkvar, *choices)
Label(mainframe, text="Choose a dish").grid(row =1, column =1)
popupMenu.grid(row =2, column =1)# on change dropdown valuedef change_dropdown(*args):
print( tkvar.get())# link function to change dropdown
tkvar.trace('w', change_dropdown)
root.mainloop()
It starts by creating a Tk object and pass it to a tkinter frame created with Frame()
Prerequisites Kali Linux Prior experience with wireless hacking You will also need to install a tool (bridge utils) which doesn't come pre-installed in Kali. No big deal- apt-get install bridge-utils Objectives The whole process can be broken down into the following steps- Finding out about the access point (AP) you want to imitate, and then actually imitating it (i.e. creating another access point with the same SSID and everything). We'll use airmon-ng for finding necessary info about the network, and airbase-ng to create it's twin . Forcing the client to disconnect from the real AP and connecting to yours. We'll use aireplay-ng to deauthenticate the client, and strong signal strength to make it connect to our network. Making sure the client doesn't notice that he connected to a fake AP. That basically means that we have to provide internet access to our client after he has connected to the fake wireless network. For that we will need to have i...
Cloning a card: Sim cards are manufactured on the basis of 3 algorithms COMP128v1,COMP128v2 and COMP128v3 now an important note currently only COMP128v1 version sim cards can be cloned ,since this is the only algorithm which has been cracked by users, bear in mind that 70% of all the sim cards we use are COMP128v1 . 1. Buy a SIM card Reader 2. Need a Blank SIM card or super SIM card 3. Download and install MagicSIM 4. Download and install USB SIM Card Reader Software 3.0.1.5 6. Go in phone tools, select SIM card, then select unlock SIM, it will prompt for a code. 7 Call network provider, they will ask for your phone number, your account info, name and security code, then they will ask why you want to unlock your SIM card, just tell them you need to unlock your SIM to get it to work with your overseas phone or something. 8. Once they give you the SIM unlock code, enter it, and it will say SIM unlocked. 9. Remove the SIM from your phone, place it in the card...
Comments
Post a Comment