<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Anjali Kumawat</title>
    <description>The latest articles on DEV Community by Anjali Kumawat (@anjalikumawat2002).</description>
    <link>https://dev.to/anjalikumawat2002</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F740049%2Fb295a827-2d7d-4e24-94b8-f3164047826a.jpeg</url>
      <title>DEV Community: Anjali Kumawat</title>
      <link>https://dev.to/anjalikumawat2002</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anjalikumawat2002"/>
    <language>en</language>
    <item>
      <title>GUI in Python Using Tkinter</title>
      <dc:creator>Anjali Kumawat</dc:creator>
      <pubDate>Fri, 10 Dec 2021 08:11:11 +0000</pubDate>
      <link>https://dev.to/anjalikumawat2002/gui-in-python-using-tkinter-gfa</link>
      <guid>https://dev.to/anjalikumawat2002/gui-in-python-using-tkinter-gfa</guid>
      <description>&lt;h2&gt;
  
  
  GUI in Python
&lt;/h2&gt;

&lt;p&gt;Python libraries to create Graphical Interfaces :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tkinter&lt;/li&gt;
&lt;li&gt;Python QT&lt;/li&gt;
&lt;li&gt;wxPython&lt;/li&gt;
&lt;li&gt;Kivy&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tkinter is an inbuilt Python module used to create simple GUI apps.&lt;/p&gt;

&lt;p&gt;Tk provides following widgets :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;button&lt;/li&gt;
&lt;li&gt;canvas&lt;/li&gt;
&lt;li&gt;checkbutton&lt;/li&gt;
&lt;li&gt;Combobox&lt;/li&gt;
&lt;li&gt;entry&lt;/li&gt;
&lt;li&gt;frame&lt;/li&gt;
&lt;li&gt;label&lt;/li&gt;
&lt;li&gt;labelframe&lt;/li&gt;
&lt;li&gt;listbox&lt;/li&gt;
&lt;li&gt;menu&lt;/li&gt;
&lt;li&gt;menubutton&lt;/li&gt;
&lt;li&gt;message&lt;/li&gt;
&lt;li&gt;notebook&lt;/li&gt;
&lt;li&gt;tk_optionmenu&lt;/li&gt;
&lt;li&gt;panedwindow&lt;/li&gt;
&lt;li&gt;progressbar&lt;/li&gt;
&lt;li&gt;radiobutton&lt;/li&gt;
&lt;li&gt;scale&lt;/li&gt;
&lt;li&gt;scrollbar&lt;/li&gt;
&lt;li&gt;separator&lt;/li&gt;
&lt;li&gt;sizegrip&lt;/li&gt;
&lt;li&gt;spinbox&lt;/li&gt;
&lt;li&gt;text&lt;/li&gt;
&lt;li&gt;treeview&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It provided the following top-level windows :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;tk_chooseColor&lt;/li&gt;
&lt;li&gt;tk_chooseDirectory&lt;/li&gt;
&lt;li&gt;tk_dialog&lt;/li&gt;
&lt;li&gt;tk_getOpenFile&lt;/li&gt;
&lt;li&gt;tk_getSaveFile&lt;/li&gt;
&lt;li&gt;tk_messageBox&lt;/li&gt;
&lt;li&gt;tk_popup&lt;/li&gt;
&lt;li&gt;toplevel&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tk also provides three geometry managers :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;​   place  -  It positions widgets at absolute locations&lt;/li&gt;
&lt;li&gt;​    grid    -  It arranges widgets in a grid&lt;/li&gt;
&lt;li&gt;​    pack  -  It packs widgets into a cavity&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Basics of tkinter
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt; import tkinter module&lt;/li&gt;
&lt;li&gt; create the main window (container)&lt;/li&gt;
&lt;li&gt; Add any number of widgets to the main window&lt;/li&gt;
&lt;li&gt; Enter the main event loop&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Eg.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import tkinter
window = Tkinter.Tk()          # creates main window
window.title("GUI")
label = tkinter.Label(window , text="Hello World !!").pack()
window.mainloop()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;mainloop() is used when our application is ready to run. mainloop() is an infinite loop used to run the application, wait for an event to occur and process the event till the window is not closed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Widgets
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Button
&lt;/h3&gt;

&lt;p&gt;It is used to add a button in our application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;window = Button(master, option=value)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;master&lt;/strong&gt; represents the parent window.&lt;/p&gt;

&lt;p&gt;activebackground    :   sets the background color when button is under the cursor.&lt;/p&gt;

&lt;p&gt;activeforeground     :    sets the foreground color when button is under the cursor.&lt;/p&gt;

&lt;p&gt;bg                          :    sets normal background color&lt;/p&gt;

&lt;p&gt;fg                          :     sets the foreground color&lt;/p&gt;

&lt;p&gt;command            :     to call a function&lt;/p&gt;

&lt;p&gt;font                        :     sets the font of button label&lt;/p&gt;

&lt;p&gt;image                    :     sets the image on the button&lt;/p&gt;

&lt;p&gt;width                     :     sets the width of the button&lt;/p&gt;

&lt;p&gt;height                  :     sets the height of the button&lt;/p&gt;

&lt;p&gt;justify                   :     LEFT , RIGHT , CENTER&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import tkinter as tk
window = tk.Tk()
window.title("Python")
button = tk.Button(window , text = 'GUI',width = 25,command = window.destroy)
button.pack()
window.mainloop()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output is :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F62aefbj9ak9pabk98zwa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F62aefbj9ak9pabk98zwa.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Label
&lt;/h3&gt;

&lt;p&gt;It is used to display text or image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;window = Label(master,option=value)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;bg               :       sets the normal background color&lt;br&gt;
command     :        to call a function&lt;br&gt;
font              :      sets the font of Label text &lt;br&gt;
image          :       sets the image on the Label&lt;br&gt;
width           :        sets the width of the Label&lt;br&gt;&lt;br&gt;
height           :     sets the height of the Label&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from tkinter import *
root = Tk()
l1 = Label(root,text="GUI Python",bg="pink",width = 25)
l1.pack()
root.mainloop()

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output is :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frp2agtp2g03s17a008c5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frp2agtp2g03s17a008c5.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Entry
&lt;/h3&gt;

&lt;p&gt;(Text Field)&lt;/p&gt;

&lt;p&gt;It is used to input single line of text.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;window = Entry(master,option=value)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;bg      :       sets the background color&lt;/p&gt;

&lt;p&gt;fg      :       sets the foreground color&lt;/p&gt;

&lt;p&gt;font        :       sets the font for widget&lt;/p&gt;

&lt;p&gt;justify :       LEFT , RIGHT , CENTER&lt;/p&gt;

&lt;p&gt;command :       to call a function&lt;/p&gt;

&lt;p&gt;width       :       sets the width of widget&lt;/p&gt;

&lt;p&gt;height      :       sets the height of widget&lt;/p&gt;

&lt;p&gt;show        :       Normally, the characters that the user types appear in the entry. To make a  .password.   entry that echoes each character as (show = "*")&lt;/p&gt;

&lt;h4&gt;
  
  
  Methods of Entry
&lt;/h4&gt;

&lt;p&gt;delete(start,end)           :   delete a character or range of characters&lt;/p&gt;

&lt;p&gt;get()                           :     returns the text of widget&lt;/p&gt;

&lt;p&gt;insert(index,string)     :     inserts text at the specified index&lt;/p&gt;

&lt;p&gt;select_range(start,end) :     selects specified range.&lt;/p&gt;

&lt;p&gt;select_present()            :     returns True if there is a selection,false otherwise&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from tkinter import *
master = Tk()
l1=Label(master,text='first Name')
l1.grid(row=0)
l2=Label(master,text='Last Name')
l2.grid(row=1)
e1=Entry(master)
e2=Entry(master)
e1.grid(row=0,column=1)
e2.grid(row=1,column=1)
mainloop()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output is :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F10au0b7qovh4bhnc781p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F10au0b7qovh4bhnc781p.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Text
&lt;/h3&gt;

&lt;p&gt;It is used to edit multi line text and formate the way it has to be displayed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;t = Text(master,option = value)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;highlightcolor      :       set the color of focus highlight&lt;/p&gt;

&lt;p&gt;insertbackground  :     set the background of the widget&lt;/p&gt;

&lt;p&gt;bg                       :      sets the normal background color&lt;/p&gt;

&lt;p&gt;fg                        :     sets the foreground color&lt;/p&gt;

&lt;p&gt;bd                       :      sets width of the border around the widget. (Default is 2 pixels)&lt;/p&gt;

&lt;p&gt;font                       :        sets the font&lt;/p&gt;

&lt;p&gt;image                  :        sets the image&lt;/p&gt;

&lt;p&gt;width                   :       sets the width (in pixels)&lt;/p&gt;

&lt;p&gt;height                 :        sets the height (in lines)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from tkinter import *
root = Tk()
t = Text(root , height = 4,width=40)
t.pack()
t.insert(END,'ANJALI KUMAWAT \nCOMPUTER SCIENCE UNDERGRAD \nGWOC"21" CONTRIBUTOR')
mainloop()

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output is :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm244z16lq36nd428cfnk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm244z16lq36nd428cfnk.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Methods of Text
&lt;/h4&gt;

&lt;p&gt;delete(start,end)   -   deletes a specific character or a range of text&lt;br&gt;
get(start,end)         -       returns a specific character or a range of text&lt;br&gt;
insert(index,string)   -       inserts text at the specified index&lt;/p&gt;
&lt;h3&gt;
  
  
  CheckButton
&lt;/h3&gt;

&lt;p&gt;It is used to display a number of options to a user as toggle buttons.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;window = CheckButton(master , option = value)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;bg              :       sets background color&lt;/p&gt;

&lt;p&gt;fg               :      sets foreground color&lt;/p&gt;

&lt;p&gt;command :       to call a function&lt;/p&gt;

&lt;p&gt;font              :     sets the font&lt;/p&gt;

&lt;p&gt;image         :     sets the image&lt;/p&gt;

&lt;p&gt;cffvalue        :       A checkbutton's associated control variable will be &lt;strong&gt;set to 0&lt;/strong&gt; when it is cleared(off).We can supply an alternate value for the off state.&lt;/p&gt;

&lt;p&gt;onvalue     :       A checkbutton's associated control variable will be &lt;strong&gt;set to 1&lt;/strong&gt; when it is set(on).We can supply an alternate value for the on state.&lt;/p&gt;

&lt;p&gt;state            :      Default is &lt;strong&gt;state=NORMAL&lt;/strong&gt; but we can use &lt;strong&gt;state=DISANLED&lt;/strong&gt; to grey out the control and make is unresponsive.&lt;/p&gt;

&lt;p&gt;variable        :       This is control variable associated with checkbutton that tracks the current state of widget.Normally this variable is an IntVar and 0 means cleared and 1 means set.&lt;/p&gt;

&lt;p&gt;Width           :       sets the width of widget.&lt;/p&gt;

&lt;h4&gt;
  
  
  Methods of checkbutton
&lt;/h4&gt;

&lt;p&gt;Deselect()      -       clears the checkbutton&lt;br&gt;
Select()        -       selects the checkbutton&lt;br&gt;
Toggle()            -       reverses the state(on/off)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from tkinter import *
root = Tk()
var1 = IntVar()
var2 = IntVar()
c1 = Checkbutton(root,text = "like Mango ? ",variable = var1,onvalue = 1,offvalue = 0,width = 40)
c2 = Checkbutton(root,text = "like Orange ? ",variable = var2,onvalue = 1,offvalue = 0,width = 40)
c1.pack()
c2.pack()
root.mainloop()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output is :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnz2bfbyfevkmy4ki0zas.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnz2bfbyfevkmy4ki0zas.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  RadioButton
&lt;/h3&gt;

&lt;p&gt;It is used to offer multiple choice option to the used and user can select one option.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;window = RadioButton(master,option=value)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;bg              :       sets the background color&lt;/p&gt;

&lt;p&gt;fg               :      sets foreground color&lt;/p&gt;

&lt;p&gt;command :       to call a function&lt;/p&gt;

&lt;p&gt;font              :     sets the font&lt;/p&gt;

&lt;p&gt;image         :     sets the image&lt;/p&gt;

&lt;p&gt;width           :       sets the width&lt;/p&gt;

&lt;p&gt;variable        :       variable associated with the Radiobuttons.&lt;/p&gt;

&lt;p&gt;value           :       when a radiobutton is selected by user,its control variable is set to its associated value. If the control variable is an IntVar , give each radiobutton in the group a different integer value option. If the control variable is a StringVar,give each radiobutton a different string value option.&lt;/p&gt;

&lt;h4&gt;
  
  
  Methods of Radiobutton
&lt;/h4&gt;

&lt;p&gt;select()        -       selects Radiobutton&lt;br&gt;
deselect()      -       deselects Radiobutton&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from tkinter import *

def select():
    if choice.get()==1:
        order = "Large Pizza"
    elif choice.get()==2:
        order = "Medium Pizza"
    else:
        order = "Small Pizza"
    selection = "You have ordered "+order
    label.config(text=selection)

root = Tk()
root.title("Pizza Corner")
choice = IntVar()
rbLarge = Radiobutton(root, text = "Large Pizza",font=20,variable=choice,value=1,command=select)
rbMedium = Radiobutton(root, text = "Medium Pizza",font=20,variable=choice,value=2,command=select)
rbSmall = Radiobutton(root, text = "Small Pizza",font=20,variable=choice,value=3,command=select)
rbLarge.pack(anchor=W)
rbMedium.pack(anchor=W)
rbSmall.pack(anchor=W)
label = Label(root,text="Choose pizza that you want!!",font=35)
label.pack()
mainloop()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output is :&lt;/p&gt;

&lt;p&gt;When we are not clicking on any RadioButton - &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwqcqcm115yhhvi3kjfqs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwqcqcm115yhhvi3kjfqs.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we are clicking on any RadioButton then -&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbcgpr5nosgxnuvu2emz6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbcgpr5nosgxnuvu2emz6.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  SpinBox
&lt;/h3&gt;

&lt;p&gt;It is used to select a value from fixed number of values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;window = Spinbox(root,option=value)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;bg              :       sets the background color&lt;/p&gt;

&lt;p&gt;fg               :      sets foreground color&lt;/p&gt;

&lt;p&gt;font              :     sets the font&lt;/p&gt;

&lt;p&gt;justify       :     LEFT,RIGHT,CENTER&lt;/p&gt;

&lt;p&gt;width         :     sets the width for widget&lt;/p&gt;

&lt;p&gt;from_        :      sets the minimum value&lt;/p&gt;

&lt;p&gt;to             :        sets the maximum value&lt;/p&gt;

&lt;h4&gt;
  
  
  Methods for Spinbox
&lt;/h4&gt;

&lt;p&gt;get()       -       returns the value&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from tkinter import *

def select():
    string = "Selection is "+str(sp.get())
    l.config(text=string)

root = Tk()
sp = Spinbox(root,from_=0,to=10,command=select,width = 15,font=30)
sp.pack()
l=Label(root,text=" ")
l.pack()
mainloop()

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​Output is :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwsvyvemguvt4i61yatrg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwsvyvemguvt4i61yatrg.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Keep Learning......&lt;br&gt;
Keep Coding......👩‍💻❤️🙌&lt;/p&gt;

</description>
      <category>programming</category>
      <category>tutorial</category>
      <category>python</category>
      <category>beginners</category>
    </item>
    <item>
      <title>EOL : Python Syntax Error</title>
      <dc:creator>Anjali Kumawat</dc:creator>
      <pubDate>Tue, 16 Nov 2021 18:27:11 +0000</pubDate>
      <link>https://dev.to/anjalikumawat2002/eol-python-syntax-error-3fl0</link>
      <guid>https://dev.to/anjalikumawat2002/eol-python-syntax-error-3fl0</guid>
      <description>&lt;h2&gt;
  
  
  EOL
&lt;/h2&gt;

&lt;p&gt;EOL == End Of Line&lt;/p&gt;

&lt;p&gt;An EOL error indicatesthat Python interpreter expected a particular character or set of characters to have occurred in specific line of code, but that those characters were not found before the end of the line . This results in Python stopping the program execution and throwing a syntax error .The EOL error signifies that the Interpreter of Python reached the end of the line while scanning the string literal.&lt;/p&gt;

&lt;h2&gt;
  
  
  syntaxerror : Eol while scanning string literal
&lt;/h2&gt;

&lt;p&gt;Let’s take a look at our error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;syntaxerror: EOL while scanning string literal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a syntax error is encountered, Python stops executing a program and gives a error . This is because the Python interpreter needs you to rectify the issue before it can read the rest of your code.&lt;/p&gt;

&lt;p&gt;This error is commonly caused by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Strings that span multiple lines using the wrong syntax&lt;/li&gt;
&lt;li&gt;Missing quotation marks&lt;/li&gt;
&lt;li&gt;Mismatching quotation marks&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What is String Literal in Python?
&lt;/h3&gt;

&lt;p&gt;String literal is a set of characters enclosed between quotation marks (“). All the characters are noted as a sequence. In Python, you can declare &lt;a href="https://docs.python.org/3/library/string.html?highlight=string#module-string"&gt;string literals&lt;/a&gt; using three types, single quotation marks (‘ ‘), double quotation marks (” “), and triple quotation marks (“”” “””). Strings are arrays and their characters can be accessed by using square brackets. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;String Literal Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exampleA = 'Single Quotes String'
exampleB = "Single Quotes String"
exampleC = """Single Quotes String"""

print(exampleA[0])  # it will print S
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Example : Multiple Lines String
&lt;/h2&gt;

&lt;p&gt;In Python, strings can span multiple lines.  Multi-line strings must be triple quoted, or written using three quotation marks.&lt;/p&gt;

&lt;p&gt;let's look at multiple line string -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def Coder():
    message = "Welcome, Coders!
When to use iterative development? You should use iterative development only on projects that you want to succeed."
        print(message)

Coder()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output is -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SyntaxError: EOL while scanning string literal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An error is returned because a string using single or double quotes cannot span multiple lines. To solve this problem, we need to enclose our string with three single or double quotes.&lt;/p&gt;

&lt;p&gt;Now look at the correct code -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def Coder():
    message = """Welcome, Coders!
When to use iterative development? You should use iterative development only on projects that you want to succeed."""
        print(message)

Coder()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output is -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Welcome, Coders!
When to use iterative development? You should use iterative development only on projects that you want to succeed.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Example : Missing Quotation Mark
&lt;/h2&gt;

&lt;p&gt;Strings must be closed after the contents of a string have been declared. Otherwise, Python returns a syntax error. &lt;/p&gt;

&lt;p&gt;Let’s take a look at a string that is not closed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def Coder():
    message = "Welcome, Coders!
        print(message)

Coder()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's check the output -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SyntaxError: EOL while scanning string literal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An We have forgotten to close our string. If you look at the line of code where we declare the “message” variable, there is no closing string character.&lt;br&gt;
We can fix this error by closing our string using the same quotation mark that we used to open our string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def Coder():
    message = "Welcome, Coders!"
        print(message)

Coder()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Welcome, Coders!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now code runs successfully.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example : Mismatching Quotation Marks
&lt;/h2&gt;

&lt;p&gt;The type of quote you use to open a string should be the same as the type of quote you use to close a string.&lt;/p&gt;

&lt;p&gt;A syntax error is returned when the types of quotes that you use to open and close a string are different. Let’s take a look at a program that opens a string using a single quote mark (‘) and closes a string using  a double quote mark (”) :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def Coder():
    message = 'Welcome, Coders!"
        print(message)

Coder()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SyntaxError: EOL while scanning string literal
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can fix this problem by making our quotations match. We’re going to change our first quotation mark to use double quotes (“):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def Coder():
    message = "Welcome, Coders!"
        print(message)

Coder()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Welcome, Coders!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now our code runs successfully.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion: EOL While Scanning String Literal
&lt;/h2&gt;

&lt;p&gt;Strings have helpful in thousands of ways in Python. As using them can provide easy access to a sequence of characters and their attributes. The only problem is that you have to take care of their syntax. Any invalid syntax and invalid backslashes in the string can cause EOF errors to appear. To avoid this error, follow all the steps from the post above.&lt;/p&gt;

&lt;p&gt;Keep Coding......&lt;br&gt;
Keep learning......💻&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>python</category>
    </item>
    <item>
      <title>Python : OS Module </title>
      <dc:creator>Anjali Kumawat</dc:creator>
      <pubDate>Wed, 10 Nov 2021 18:07:33 +0000</pubDate>
      <link>https://dev.to/anjalikumawat2002/python-os-module-ccb</link>
      <guid>https://dev.to/anjalikumawat2002/python-os-module-ccb</guid>
      <description>&lt;p&gt;The os module is a part of the standard library, or stdlib, within Python 3.&lt;/p&gt;

&lt;p&gt;Python &lt;strong&gt;os&lt;/strong&gt; module provides methods that help us to perform file processing operations. Let’s explore these basic functions one by one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using os
&lt;/h2&gt;

&lt;p&gt;Before you use the os module, you first need to bring it up by means of the Python import command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import os
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you try to run os without importing it, you will see an error message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NameError: name 'os' is not defined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To get a list of functions supported by os module, run the below command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(dir(os))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Files
&lt;/h2&gt;

&lt;p&gt;Some of the methoods of the &lt;strong&gt;os&lt;/strong&gt; module to work with files.&lt;/p&gt;

&lt;h3&gt;
  
  
  rename() method :
&lt;/h3&gt;

&lt;p&gt;It is used to rename a file or directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;os.rename(old_filename,new_filename)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;os.rename(“file.txt”, “user.txt”)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  remove() method :
&lt;/h3&gt;

&lt;p&gt;It is used to delete the file.&lt;br&gt;
&lt;strong&gt;Path&lt;/strong&gt; : This is a path-like object which represents a file system path. This path-like object is either a string or bytes object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;os.remove(path_of_file)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;os.remove(“d1/user.txt”)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Directories
&lt;/h2&gt;

&lt;h3&gt;
  
  
  CWD :
&lt;/h3&gt;

&lt;p&gt;CWD == "Current working directory"&lt;/p&gt;

&lt;h3&gt;
  
  
  getcwd() method :
&lt;/h3&gt;

&lt;p&gt;returns current directory.&lt;br&gt;
or &lt;br&gt;
To check the path of the current working directory, we will use the getcwd method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(os.getcwd())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;  The folder where the Python script is running is known as the Current Directory. This is not the path where the Python script is located.&lt;/p&gt;

&lt;h3&gt;
  
  
  mkdir() method :
&lt;/h3&gt;

&lt;p&gt;It is used to create a directory in current directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;os.mkdir("d1")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method raises FileExistsError if the directory to be created already exists.&lt;/p&gt;

&lt;h3&gt;
  
  
  chdir() method :
&lt;/h3&gt;

&lt;p&gt;Suppose, we have a folder, for example, info, inside our current directory, we can switch to the info folder, using the chdir function. or It is used to change the current directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;os.chdir("info")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  rmdir() method :
&lt;/h3&gt;

&lt;p&gt;It is used to delete a directory. The directory must be empty before it is deleted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;os.rmdir("dirname")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  listdir() method :
&lt;/h3&gt;

&lt;p&gt;Returns a list containing names of files and subdirectories in the specified directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(os.listdir())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep Learning!!&lt;br&gt;
Keep Coding....❤️👩‍💻&lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>python</category>
    </item>
    <item>
      <title>How to Overcome from TLE Error in competitive programming?</title>
      <dc:creator>Anjali Kumawat</dc:creator>
      <pubDate>Sun, 07 Nov 2021 18:30:01 +0000</pubDate>
      <link>https://dev.to/anjalikumawat2002/how-to-overcome-from-tle-error-in-competitive-programming-26p9</link>
      <guid>https://dev.to/anjalikumawat2002/how-to-overcome-from-tle-error-in-competitive-programming-26p9</guid>
      <description>&lt;h2&gt;
  
  
  What is &lt;strong&gt;TLE&lt;/strong&gt;?
&lt;/h2&gt;

&lt;p&gt;TLE == "Time Limit Exceed"&lt;/p&gt;

&lt;p&gt;Many programmers always argue that the problems in Competitive Programming always end up with TLE(Time Limit Exceed). The main problem with this error is that it will not allow you to know that your solution would reach to correct solution or not! &lt;/p&gt;

&lt;p&gt;The main problem in TLE is, you will not be able to know whether your code is generating the right output or not. and when output is right and that time code gives TLE ,the online judge has to stop your submission from running after a particular time period.&lt;/p&gt;

&lt;p&gt;Because they first check your compiler error (if any) then runtime error (if any), then TLE (if any) and at last right or wrong answer your code is generating.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why &lt;strong&gt;TLE&lt;/strong&gt; comes?
&lt;/h2&gt;

&lt;p&gt;To understand Time Limit Exceeded(TLE), understanding how the online judge works will help. The online judge allocates resources like memory and CPU for evaluating every submission. &lt;/p&gt;

&lt;p&gt;There might be various reasons behind it that your &lt;strong&gt;TLE&lt;/strong&gt; is coming. Few points are :&lt;/p&gt;

&lt;h3&gt;
  
  
  Online Judge :
&lt;/h3&gt;

&lt;p&gt;An online judge ( Problem setter the problem) gives TLE on a problem because there are some restrictions in each input with a specific time limit. If your program exceeds that time limit you will get TLE.&lt;/p&gt;

&lt;h3&gt;
  
  
  Your program is too slow :
&lt;/h3&gt;

&lt;p&gt;The most common reason that you would get a TLE is because your program is too slow.&lt;br&gt;
Read the bounds in the input carefully before writing your program, and try to figure out which inputs will cause your program to run the slowest.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Python&lt;/strong&gt;, you could try speeding up your solutions by adding the following two lines to the start of your file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import psyco
    psyco.full()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To add fast IO in your code you have to write the following lines in main() in your code in &lt;strong&gt;C/C++&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ios_base::sync_with_stdio(false); 
    cin.tie(NULL) ;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Java&lt;/strong&gt; Do not use Scanner class, use BufferedReader instead.&lt;/p&gt;

&lt;h3&gt;
  
  
  Server Configuration:
&lt;/h3&gt;

&lt;p&gt;Sometimes, the server takes time to run your code. So, it might depend on their CPU, OS, etc. For this reason, the different platform (different servers like practice, CodeChef , HackerEarth etc..)gives you TLE in different cases.&lt;br&gt;
By estimating the maximum value of N (N is the total number of instructions of your whole code), you can roughly estimate the TLE would occur or not in 1 sec.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MAX value of N                       Time complexity
   10^8                              O(N) Border case
   10^7                     O(N) Might be accepted
   10^6                              O(N) Perfect
   10^5                              O(N * logN)
   10^4                              O(N ^ 2)
   10^2                              O(N ^ 3)
   10^9                              O(logN) or Sqrt(N)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; a loop value (N) cannot be greater than 10^9 if N is an integer. Because an integer can take up to 10^9.&lt;/p&gt;

&lt;p&gt;So after analyzing this Table you can estimate your Time complexity roughly and try to make your code within the upper bound limit.&lt;/p&gt;

&lt;h4&gt;
  
  
  All the best !!
&lt;/h4&gt;

&lt;h4&gt;
  
  
  Keep Coding......❤
&lt;/h4&gt;

</description>
      <category>programming</category>
      <category>python</category>
      <category>cpp</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
