0%
Loading ...

Python Tkinter

This tutorial category contains all the tutorials related to Python Tkinter.

Python Tkinter TopLevel

In this tutorial, we will learn about Python Tkinter TopLevel. Tkinter TopLevel is used to show top-level screen and which directly managed by the window manager. The main motive of showing top-level window is to show extra information on-screen, pop-up or to show a group of widgets in a different window. Syntax to add Python Tkinter TopLevel: w = Toplevel(options) options: Here is the list of most commonly used options for this widget. Example Program of Python Tkinter TopLevel: from tkinter import * mainWindow= Tk() mainWindow.geometry(“200×200”) def open(): top = Toplevel(mainWindow) top.mainloop() button = Button(mainWindow, text = “open”, command = open) button.place(x=75,y=50) mainWindow.mainloop() Various possible options in Python Tkinter TopLevel: OPTION DESCRIPTION bg This option helps us to set the normal background colour of the window. bd This option is used to set the size of the border around the widget. cursor This option helps us to set the style of cursor like an arrow, dot etc font This option is used to set font type in the widget. fg This option is used to set the foreground colour widget. height This helps us to set the height of the window. relief This helps us to set the type of the window. width This helps us to set the width of the window. Tkinter TopLevel Methods: After learning about various available options in Python Tkinter TopLevel Its time to check out some available methods for Tkinter TopLevel widget. METHODS DESCRIPTION deiconify() This method is used to display the window on the screen. frame() This method returns a window identifier which is system-specific. group(window) This method is used to add a window in the mentioned window group. iconify() This method is used to turns the window into an icon. protocol(name,function) This method is used to define a method which can be called for a specific protocol. state() This method returns the current state of the window. transient(master) This method is used to convert this window to a transient window. withdraw() This method is used to remove the window from the screen. maxsize(w,h) This method is used to define the maximum size of the window(w=width, h=height). minsize(w,h) This method is used to define the minimum size of the window(w=width, h=height). resizable(w,h) This method is used to define whether a widow can be resized or not. title(string) This method is used to set the title for the window. Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Python Tkinter TopLevel Read More »

Python Tkinter Text

In this tutorial, we will learn about Python Tkinter Text. The Tkinter Text widget is used to show multi-line text in the application. The best thing about this Text widget we can set the style of text in this widget such as we can change colour and font-style. We can also use the windows and images with the Text. Check out the following syntax example to know how we can add a text widget in our Python application. Syntax to add Python Tkinter Text: w = Text (master, options) master: This represents the parent window. options: Here is the list of most commonly used options for this widget. Example Program of Python Tkinter Text: # importing tkinter lib from tkinter import * mainWindow = Tk() mainWindow.geometry(“320×180”) text = Text(mainWindow, height = 5, width = 35) lable = Label(mainWindow, text = “Owlbuddy.com”) lable.config(font =(“Arial”, 14)) text.insert(END, “Learn Programming languages here..”) text.tag_add(“style”, “1.0”, “1.50”) text.tag_config(“style”, background=”skyblue”, foreground=”black”) lable.pack() text.pack() mainWindow.mainloop() Various possible options in Python Tkinter Text: OPTION DESCRIPTION bg This option helps us to set the normal background colour of the widget. bd This option is used to set the size of the border around the widget. cursor This option helps us to set the style of cursor like an arrow, dot etc exportselection This option is used to export selected text to selection in the window manager. font This option is used to set font type in the widget. fg This option helps us to set the foreground colour of the widget. height This option helps us to set the height of the widget. highlightbackground This option is used to set the highlight colour when the widget has no focus. highlightcolor This option is used to set the highlight colour when the widget has focus. highlightthickness This option is used to set the thickness of the highlight focus. By default highlightthickness=1. insertbackground This option is used to set the colour of the insertion cursor. By default insertbackground=black. insertborderwidth This option is used to set the width of the border around the insertion cursor. By default insertborderwidth=0. insertofftime This option is used to set time around in which during which the insertion cursor is in off blink cycle. By default inserontime=300 milliseconds. insertontime This option is used to set time around in which during which the insertion cursor is in on blink cycle. By default inserontime=600 milliseconds. insertwidth This option is used to set the width of the insertion cursor.By default insertwidth= 2. padx This option helps us to set the space left and right. pady This option helps us to set space above and below. relief This helps us to set the 3D style text which is by default is relief=SUNKEN. selectbackground This option is used to set the background colour of selected text. selectborderwidth This option is used to set the border of the width around the selected text. spacing1 This option is used to set the vertical space above the lines. spacing2 This option is used to set vertical space between the lines when a logical line wraps. spacing3 This option is used to set vertical space below the text. state We can makeout widget disable It will not respond to mouse or keyword events just set state=DISABLED. tabs This option helps us to the position of tab characters. width This helps us to set the width of the widget. wrap This option helps us to wrap up the line lines with so much text into multiple lines. xscrollcommand This option used to let the user scroll the Text horizontally. yscrollcommand This option used to let the user scroll the Text vertically. Python Tkinter Text Methods: After learning about various available options in Python Tkinter Text Its time to check out some available methods for Tkinter Text widget. METHOD Description delete(startindex [,endindex]) This method used to delete all the characters between specified index numbers. get(startindex [,endindex]) This method returns all the characters between specified index numbers. index(index) This method is used to get the absolute index of the specified index. insert(index [,string]…) This method is used to set the specified string at the specified index. see(index) This method returns true or false after checking the text at the specified location visible or not. Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Python Tkinter Text Read More »

Python Tkinter Spinbox

In this tutorial, we will learn about Python Tkinter Spinbox. Tkinter Spinbox is an entry widget which is used to ask the user to choose one from fixed values. Syntax to add Python Tkinter Spinbox: w = Spinbox( master, option) master: This represents the parent window. options: Here is the list of most commonly used options for this widget. Example Program of Python Tkinter Spinbox: from tkinter import * masterWindow = Tk() masterWindow.geometry(“320×180”) spinBox = Spinbox(masterWindow, from_=1, to=10) spinBox.pack() mainloop() Various possible options in Python Tkinter Spinbox: OPTION DESCRIPTION activebackground This option is used to set the colour of the slider and arrowheads on mouse hover. bg This option is used to set the colour of the slider and arrowheads. bd This option is used to set the size of the border around the widget. command This option is used to set the function to call on the move of the scrollbar. cursor This option helps us to set the style of cursor like an arrow, dot etc disabledbackground This option is used to set the background colour of the widget when the widget is disabled. disabledforeground This option is used to set the background colour of the text in widget when the widget is disabled. fg This option is used to set the foreground colour(text colour) of the widget. font This option is used to set font type in the widget. format This option is used to set format string for the widget. from_ This option is used to set the starting point to show values in the widget. justify This option is used to the alignment of the widget. By default, it is LEFT. relief This helps us to set the 3D style text which is by default is relief=SUNKEN. state This option is used to set the state of the widget. such as NORMAL, DISABLED, or “readonly”. By default it is NORMAL. textvariable This option is used to set the text variable to the widget. There is no default value for this widget. to This option is used to set the last value of the valid values. validate This option is used to set the validation mode. By default, it is NONE. validatecommand This option is used to set validate callback. values This option is used to set a tuple to widget(Tuple which contain valid values). width This helps us to set the width of the widget. By default, it is 20. wrap This option helps us to wrap around and down button. xscrollcommand This option used to connect the spinbox widget to the horizontal scrollbar. Tkinter Spinbox Methods: After learning about various available options in Python Tkinter Spinbox Its time to check out some available methods for Tkinter Spinbox widget. METHODS DESCRIPTION delete(startindex [,endindex]) This method used to delete a single character or the range of values between specified index numbers. get(startindex [,endindex]) This method returns a single character or the range of values between specified index numbers. identify(x, y) This method is used to identify the widget element at the given location. index(index) This method returns the value at the specified index number. insert(index [,string]…) This method is used to insert a string at the specified index number. invoke(element) This method is used to invoke the Spinbox button. Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Python Tkinter Spinbox Read More »

Python Tkinter ScrollBar

In this tutorial, we will learn about Python Tkinter ScrollBar. Tkinter ScrollBar widget is used to make the content of other widgets scroll-able in Python application. Syntax to add Python Tkinter ScrollBar: w = Scrollbar (master, options) master: This represents the parent window. options: Here is the list of most commonly used options for this widget. Example Program of Python Tkinter ScrollBar: # importing tkinter lib from tkinter import * mainWindow = Tk() mainWindow.geometry(“320×180”) scrollbar = Scrollbar(mainWindow) scrollbar.pack( side = RIGHT, fill = Y ) mylist = Listbox(mainWindow, yscrollcommand = scrollbar.set ) for line in range(100): mylist.insert(END,str(line)) mylist.pack( side = LEFT, fill = BOTH ) scrollbar.config( command = mylist.yview ) mainWindow.mainloop() Various possible options in Tkinter ScrollBar: Option Description activebackground This option is used to set background color of widget under focus. bg This option helps us to set the normal background colour of the widget. bd This option helps us to set the border size around the widget. command This option helps us to mention a function to every time when ScrollBar will change its state. cursor This option helps us to set the style of cursor like an arrow, dot etc elementborderwidth This option is used to set a border around arrowheads and slider. By default elementborderwidth=1. highlightbackground This option is used to set the color of the focus highlight when the widget is not having the focus. highlightcolor This option is used to set highlight colour shown to the widget under focus. highlightthickness This option is used to set the thickness of hight focus. By default highlightthickness=1. jump This option is used to control the behaviour of the scroll jump. orient This option is used to set the orientation of scroll bar HORIZONTAL or VERTICAL. repeatdelay This option used to controls how long button one has to be held down before the slider starts moving in that direction repeatedly. The default time is repeatdelay=300 milliseconds. repeatinterval This option is used to set the repeat interval. By default, it is 100. takefocus This option is used to set the focus of widget which is by default on. If you don’t want to keep it on you can set this option to 0. troughcolor This option is used to set the colour of the trough. width This helps us to set the width of the widget. Tkinter ScrollBar Methods: After learning about various available options in Python Tkinter ScrollBar Its time to check out some available methods for Python Tkinter ScrollBar widget. Method DESCRIPTION get() This method returns the two numbers a and b which represents the current position of the scrollbar. set ( first, last ) This method used to connect the scrollbar to the other widget. Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Python Tkinter ScrollBar Read More »

Python Tkinter Scale

In this tutorial, we will learn about Python Tkinter Scale. Tkinter Scale widget is used to create a graphical slider on the screen. This widget allows user to move scale and to select a particular value on the scale. Syntax of the Python Tkinter Scale: w = Scale (master, options) master: This represents the parent window. options: Here is the list of most commonly used options for this widget. Example of the Tkinter Scale: # importing tkinter lib from tkinter import * def show(): value = “Value is = ” + str(svar.get()) label.config(text = value) mainWindow = Tk() mainWindow.geometry(“320×180″) svar = DoubleVar() scale = Scale(mainWindow, variable = svar ) scale.pack(anchor=CENTER) button = Button(mainWindow, text=”Show Selected Value”, command=show) button.pack(anchor=CENTER) label = Label(mainWindow,pady=10) label.pack() mainWindow.mainloop() Various possible options in Python Tkinter Scale: Option Description activebackground This option is used to set background color of widget under focus. bg This option helps us to set the normal background colour of the widget. bd This option is used to set the size of border around the widget. command This option helps us to mention a function to every time when RadioButton will change its state. cursor This option helps us to set the style of cursor like an arrow, dot etc font This option is used to set font type in the widget. fg This option helps us to set the normal foreground colour of the widget. from_ This option id used to start point of scale’s range. highlightbackground This option is used to set the color of the focus highlight when the widget is not having the focus. highlightcolor This option is used to set highlight colour shown to the widget under focus. label This option is used to show a label with scale. length This option is used to set length of the scale widget.By default 100px. orient This option is used to set the orientation of Scale. relief This helps us to set the style of the border by which is default Flat. sliderlength This option is used to set length of scale slider which is normally 30px you can change it. state This option is used to set state or Scale. By default it is NORMAL. You can also set it DISABLE. tickinterval This option is used to set a tick interval in scale. to This option is used ending point of scale’s range. troughcolor This option is used to set the colour of the trough. variable This option is used to set a variable in Scale. width This helps us to set the width of the widget. Tkinter Scale Methods: After learning about various available options in Python Tkinter Scale. Its time to check out some available methods for Tkinter Scale widget. Method Description get() This method returns the current value of scale. set ( value ) This method helps us to set the value of scale. Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Python Tkinter Scale Read More »

Python Tkinter RadioButton

In this tutorial, we will learn about Python Tkinter RadioButton. Tkinter RadioButton is used to show multiple options to the user from these options user can select only one option. We can associate a different method with each RadioButton. Furthermore, we can show multiple lines or images with RadioButtons. It is important to note, to add proper functionality in RadioButtons each RadioButton must be associated with a single variable. Each RadioButton must symbolize with a single value for that particular variable. Syntax of Python Tkinter RadioButton: w = Radiobutton (master, options) master: This represents the parent window. options: Here is the list of most commonly used options for this widget. Example of Python Tkinter RadioButton: # importing tkinter lib from tkinter import * l= [“C”, “Java”, “Python”] def choice(): selection = “You have chosen : ” + l[radio.get()] message.config(text = selection) mainWindow = Tk() mainWindow.geometry(“320×150”) radio = IntVar() lb = Label(text = “Please choose one programming language:”, pady=15 ) lb.pack() c = Radiobutton(mainWindow, text=”C”, variable=radio, value=0, command=choice) c.pack( anchor = W ) java = Radiobutton(mainWindow, text=”Java”, variable=radio, value=1, command=choice) java.pack( anchor = W) python = Radiobutton(mainWindow, text=”Python”, variable=radio, value=2, command=choice) python.pack( anchor = W) message = Label(mainWindow) message.pack() mainWindow.mainloop() Various possible options in Python Tkinter RadioButton: Option Description activebackground This option is used to set background color of widget under focus. activeforeground This option is used to set foreground color of widget under focus. anchor This option helps us to set position of text inside the widget. By default value of anchor is CENTER. bg This option helps us to set normal background color of widget. bitmap This option helps us to display an image. You just have to set this option equal to an image object. borderwidth This option is used to set the width of border. command This option helps us to mention a function to every time when RadioButton will change its state. cursor This option helps us to set the style of cursor like an arrow, dot etc font This option is used to set font type in widget. fg This option helps us to set normal foreground colour of widget. height This option helps us to set height of widget. highlightcolor This option is used to set highlight color shown to the widget under focus. highlightbackground This option is used to set color of the focus highlight when the widget is not having the focus. image This option helps us to show image with radio button instead of text. justify This helps us to automatically organize the text in multiple lines. padx This option helps us to set space left and right between text and RadioButton. pady This option helps us to set space above and below. relief This helps us to set the style of the border by which is default Flat. selectcolor This option used to set color of text when radio button will selected state. selectimage This option used to display image when radio button will selected state. state This option is use to set state or RadioButton. By default it is NORMAL. You can also set it DISABLE. text This option helps us to set string source for label. textvariable This option is use to mention text source(variable.) underline This option helps us to underline specified letter of the text. value This option is used to set value of each RadioButton. variable This option is used to set variable in RadioButton. width This helps us to set the width of the widget. wraplength This option is used to wrap text into number of lines. Python Tkinter RadioButton Methods: After learning about various available options in Python Tkinter RadioButton. Its time to check out some available methods for Python Tkinter RadioButton widget. METHOD Description deselect() This method called to deselect the RadioButton. flash() This method is used to flash RadioButton between normal and active state. invoke() This method helps us to invoke the associated method with state of a RadioButton is changed. select() This method is used to select the RadioButton. Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Python Tkinter RadioButton Read More »

Python Tkinter PanedWindow

In this tutorial, we will learn about Python Tkinter PanedWindow. Tkinter PanedWindow is a widget which is used as a container. A PanedWindow can contain one or more child Panes arranged horizontally or vertically. Here each pane can contain a widget. The movable (via mouse movements)  line to divide between two panes is known as a sash. Syntax to add Python Tkinter PanedWindow: w = PanedWindow( master, option) master: This represents the parent window. options: Here is the list of most commonly used options for this widget. Example Program of Python Tkinter PannedWindow: from tkinter import * mainWindow = Tk() mainWindow.title(“PanedWindow Example”) mainWindow.geometry(‘350×200′) bigPannedWindow = PanedWindow(mainWindow, orient=HORIZONTAL) bigPannedWindow.pack(fill=BOTH, expand=1) label = Label(bigPannedWindow, text=”This is left pane”, bg=”red”) bigPannedWindow.add(label) rightPannedWindow = PanedWindow(bigPannedWindow, orient=VERTICAL) bigPannedWindow.add(rightPannedWindow) topPane = Label(rightPannedWindow, text=”This is top pane”, bg=”blue”) rightPannedWindow.add(topPane) bottomPane = Label(rightPannedWindow, text=”This is bottom pane”,bg=”orange”) rightPannedWindow.add(bottomPane) mainWindow.mainloop() Various possible options in Python Tkinter PanedWindow: OPTION DESCRIPTION bg This option is used to set the background colour of the widget. bd This option is used to set the size of the 3D border around the widget. borderwidth This option is used to set the width of the border. By default, it is 2px. cursor This option used to set the style of cursor like an arrow, dot etc handlepad This option is used to set the distance between the handle and the end of the sash. In the case of horizontal orientation,  it is used to set the distance between the top of the sash and the handle. By default this distance is 8px. handlesize This option is used to set the size of the handle. By default, it is 8px. height This used to set the height of the widget. orient This option is used to set the orientation of the PanedWindow. relief This used to set the type of the widget. sashpad This option is used to set the padding around each sash. sashrelief This option is used to set a border around the sash. By default, it is FLAT. sashwidth This option is used to set the width of the sash. By default, it is 2px. showhandle This option is used to control the visibility of handle. By default, it is false. width This option is used to set the width of the widget. Tkinter PanedWindow Methods: After learning about various available options in Python Tkinter PanedWindow. Its time to check out some available methods for Python Tkinter PanedWindow widget. METHODS DESCRIPTION add(child, options) This method is used to add a child widget to the PanedWindow. get(startindex [,endindex]) This method is used to get the text between the specified range. config(options) This method is used to configure the widget with specified options. Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Python Tkinter PanedWindow Read More »

Python Tkinter MessageBox

In this tutorial, we will learn about Python Tkinter MessageBox. Tkinter MessageBox widget is used to show a message box in the application. This widget comes with the number of functions to show perfect message according to the requirements of the application. Available Functions in MessageBox: showinfo() showwarning() showerror() askquestion() askokcancel() askyesno() askretrycancel() Syntax to add Python Tkinter MessageBox: messagebox.function_name(title, message, [options]) function_name: Here we have to write an appropriate function name according to the requirements of the application. title: This option to write the title for the MessageBox. message: This option to write the message in MessageBox. options: Here we can write various options to configure the MessageBbox. Now we will check each function of MessageBox one by one. showinfo(): The showinfo() method we can use where we want to show some information to user. from tkinter import * from tkinter import messagebox mainWindow = Tk() mainWindow.geometry(“300×200”) messagebox.showinfo(“Important”,”Here is an important info”) mainWindow.mainloop() showwarning(): This function is used to show a warning message to the user. from tkinter import * from tkinter import messagebox mainWindow = Tk() mainWindow.geometry(“300×200”) messagebox.showwarning(“Warning”,”Ohh Warning message here”) mainWindow.mainloop() showerror(): This function is used to show an error message to the user. from tkinter import * from tkinter import messagebox mainWindow = Tk() mainWindow.geometry(“300×200”) messagebox.showerror(“Error”,”Ohh Error message here”) mainWindow.mainloop() askquestion(): This function is used to ask some question to user and user can reply to this question in the form of yes or no. from tkinter import * from tkinter import messagebox mainWindow = Tk() mainWindow.geometry(“300×200”) messagebox.askquestion(“Exit”,”Do you really want to exit?”) mainWindow.mainloop() askokcancel(): This function is used when we need to get some kind of confirmation from the user. In this kind of message box user can click on “ok” or “cancel”. from tkinter import * from tkinter import messagebox mainWindow = Tk() mainWindow.geometry(“300×200”) messagebox.askokcancel(“Exit”,”Exit without save?”) mainWindow.mainloop() askyesno(): This askyesno() function is used to ask a question to the user. For which the user can reply by clicking on “yes” or “no” button. from tkinter import * from tkinter import messagebox mainWindow = Tk() mainWindow.geometry(“300×200”) messagebox.askyesno(“Apply”,”Apply Changes?”) mainWindow.mainloop() askretrycancel(): This function is use to show retry message to user to ask whether user want retry a particular task. from tkinter import * from tkinter import messagebox mainWindow = Tk() mainWindow.geometry(“300×200”) messagebox.askretrycancel(“Internet Error”,”Internet Connection interrupted.”) mainWindow.mainloop()   Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Python Tkinter MessageBox Read More »

Python Tkinter Message

In this tutorial, we will learn about Python Tkinter Message. Python Tkinter Message works same as Lable expect it can automatically wrap up content and given width. We mainly use this widget to show the multiline text. Syntax to add Python Tkinter Message: w = Message (master, options) master: This represents the parent window. options: Here is the list of most commonly used options for this widget. Example Program of Python Tkinter Message: from tkinter import * mainWindow = Tk() mainWindow.geometry(“300×150”) text = StringVar() text.set(“Hello, Welcome to Owlbuddy”) label = Message( mainWindow, textvariable=text, relief=RAISED ) label.pack() mainWindow.mainloop() Various possible options in Python Tkinter Message: Option Description anchor This option is used to set the position of text in widget The default is anchor=CENTER. bg This option helps us to set the normal background colour of the widget. bitmap This option helps us to display an image. You just have to set this option equal to an image object. bd This option is used to set the size of the border around the widget. cursor This option helps us to set the style of cursor like an arrow, dot etc font This option is used to set font type in the widget. fg This option helps us to set the normal foreground colour of the widget. height This option helps us to set the height of the widget. image This option helps us to show the image with the radio button instead of text. justify This helps us to automatically organize the text in multiple lines. padx This option helps us to set the space left and right. pady This option helps us to set space above and below. relief This helps us to set the style of the border by which is default Flat. text This option helps us to set a string source for the label. textvariable This option is used to mention text source(variable.) underline This option helps us to underline the specified letter of the text. width This helps us to set the width of the widget. wraplength This option is used to wrap text into the number of lines. Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Python Tkinter Message Read More »

Python Tkinter Menu

In this tutorial, we will learn about Python Tkinter Menu. Tkinter Menu helps us to add a menu in the Python application. we can create three kinds of the menu using Menu widget which is: pop-up, top-level and pull-down. Syntax to add Python Tkinter Menu: w = Menu (master, options) master: This represents the parent window. options: Here is the list of most commonly used options for this widget. Example Program of Python Tkinter Menu: from tkinter import * mainWindow = Tk() mainWindow.geometry(“300×150″) menubar = Menu(mainWindow) filemenu = Menu(menubar, tearoff=0) filemenu.add_command(label=”New”) filemenu.add_command(label=”Open”) filemenu.add_command(label=”Save”) filemenu.add_command(label=”Save as”) menubar.add_cascade(label=”File”, menu=filemenu) editmenu = Menu(menubar, tearoff=0) editmenu.add_command(label=”Undo”) editmenu.add_command(label=”Cut”) editmenu.add_command(label=”Copy”) editmenu.add_command(label=”Paste”) editmenu.add_command(label=”Delete”) editmenu.add_command(label=”Select All”) menubar.add_cascade(label=”Edit”, menu=editmenu) mainWindow.config(menu=menubar) mainWindow.mainloop() Various possible options in Python Tkinter Menu: Option Description activebackground This option is used to set background color of widget under focus. activeborderwidth This option is used to set width of border when widget under mouse. By default it is 1px. activeforeground This option is used to set foreground color of widget under focus. bg This option helps us to set normal background color of widget. bd This option helps us to set the border size around widget. cursor This option helps us to set the style of cursor like an arrow, dot etc. disabledforeground This option is used to disable text color of widget. font This option is used to set font type in widget. fg This option helps us to set normal foreground colour of widget. relief This helps us to set the style of the border by which is default Flat. selectcolor This option is used to set color of selected RadioButton or CheckBox. title This option is used to set the title of the window. Python Tkinter Menu Methods: After learning about various available options in Python Tkinter Menu. Its time to check out some available methods for Tkinter Menu widget. METHOD DESCRIPTION add_command(options) This method is used to add menu items in the menu widget. add_radiobutton(options) This method is used to add radio buttons in the menu widget. add_checkbutton(options) This method is used to add the check button in the menu button. add_cascade(options) This method is used to add one menu into another menu to create a hierarchical menu. add_seperator() This method is used to create a separator line in the menu. add(type, options) This method is used to add a specific menu item in the menu widget. delete(startindex, endindex) This method is used to delete all the menu items from the menu which falls between specified range, entryconfig(index, options) This method is used to modify(changing options) menu item at the given index. index(item) This method is used to get the index number of the specified menu item. insert_seperator(index) This method is used to add a separator at a specified index. type(index) This method returns the type of specified index item such as “cascade”, “checkbutton”, “command”, “radiobutton”, “separator”, or “tearoff”. Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Python Tkinter Menu Read More »

Scroll to Top
×