1+
2+ # imported necessary library
13from tkinter import *
24from tkinter import messagebox
35import tkinter .messagebox as mbox
46import tkinter as tk
57
6-
8+ # created main window
79root = Tk ()
810root .title ("Virtual Copy Paste" )
911root .geometry ('1000x700' )
1012
11-
12- def print_output ():
13- mbox .showinfo ("Text Entered" , "Text Entered :\n \n " + text_enter .get ('1.0' ,END ))
14-
15- # frame 1 ----------------------------------------------
13+ # frame 1 --------------------------- created frame 1 ------------------
1614def des_f1 ():
1715 f1 .destroy ()
1816
19-
17+ # frame 1 created which is the main window
2018f1 = Frame (root , height = 700 , width = 1000 )
2119f1 .propagate (0 )
2220f1 .pack (side = 'top' )
2321
22+ # this is for adding image in the main window
2423c = Canvas (f1 , width = 1000 , height = 700 )
2524c .pack ()
2625p1 = PhotoImage (file = 'Images/copy_paste.gif' )
2726c .create_image (0 , 100 , image = p1 , anchor = NW )
2827
28+ # for starting label
2929start1 = Label (f1 , text = 'VIRTUAL Copy Paste' , font = ("Arial" , 50 ), fg = "magenta" , underline = 0 )
3030start1 .place (x = 150 , y = 10 )
3131
32+ # created a START button
3233startb = Button (f1 , text = "START" ,command = des_f1 ,font = ("Arial" , 30 ), bg = "light green" , fg = "blue" , borderwidth = 3 , relief = "raised" )
3334startb .place (x = 180 , y = 550 )
3435# ------------------------------------------------------
3536
3637# frame 2 ---------------------------------------------
38+ # created global variable s
3739s = ""
3840
41+ # function for clearing the default text from text1 when put cursor on it
3942firstclick1 = True
4043def on_text_enter_click (event ):
4144 """function that gets called whenever entry1 is clicked"""
@@ -44,16 +47,19 @@ def on_text_enter_click(event):
4447 firstclick1 = False
4548 text1 .delete ('1.0' , "end" ) # delete all the text in the entry
4649
50+ # function for copying the text
4751def copy_text ():
4852 global s
4953 s = s + text1 .get ("1.0" , "end-1c" )
5054
55+ # function for seeing the copied text
5156def see_text ():
5257 if (s == "" ):
5358 mbox .showerror ("Error" , "You haven't copied anything!" )
5459 else :
5560 mbox .showinfo ("Copied Text" , "COPIED TEXT :\n \n " + s )
5661
62+ # function for pasting the text
5763def paste_text ():
5864 global s
5965 if (s == "" ):
@@ -63,35 +69,40 @@ def paste_text():
6369 text2 .insert (END , s )
6470 s = ""
6571
66-
72+ # created frame 2
6773f2 = Frame (root , height = 700 , width = 1000 )
6874f2 .propagate (0 )
6975f2 .pack (side = 'top' )
7076
77+ # created first textarea
7178text1 = tk .Text (f2 , height = 20 , width = 35 , font = ("Arial" , 15 ), bg = "light yellow" , fg = "brown" ,borderwidth = 3 , relief = "solid" )
7279text1 .insert (END , 'Enter any text here and Copy it...' ) # default line in text area, can be cleared when touched
7380text1 .bind ('<FocusIn>' , on_text_enter_click )
7481text1 .place (x = 50 , y = 20 )
7582
83+ # created second textarea
7684text2 = tk .Text (f2 , height = 20 , width = 35 , font = ("Arial" , 15 ), bg = "light yellow" , fg = "brown" ,borderwidth = 3 , relief = "solid" )
7785text2 .insert (END , 'Paste the copied text here...' ) # default line in text area, can be cleared when touched
7886text2 .place (x = 550 , y = 20 )
7987
80-
88+ # created COPY button
8189copyb = Button (f2 , text = "COPY" ,command = copy_text ,font = ("Arial" , 30 ), bg = "light green" , fg = "blue" , borderwidth = 3 , relief = "raised" )
8290copyb .place (x = 100 , y = 550 )
8391
92+ # Created SEE button
8493seeb = Button (f2 , text = "SEE" ,command = see_text ,font = ("Arial" , 30 ), bg = "light green" , fg = "blue" , borderwidth = 3 , relief = "raised" )
8594seeb .place (x = 300 , y = 550 )
8695
96+ # created a PASTE button
8797pasteb = Button (f2 , text = "PASTE" ,command = paste_text ,font = ("Arial" , 30 ), bg = "light green" , fg = "blue" , borderwidth = 3 , relief = "raised" )
8898pasteb .place (x = 480 , y = 550 )
8999
100+ # function for exiting
90101def exit_win ():
91102 if messagebox .askokcancel ("Exit" , "Do you want to exit?" ):
92103 root .destroy ()
93104
94-
105+ # created a exit button
95106exitb = Button (root , text = "EXIT" ,command = exit_win ,font = ("Arial" , 30 ), bg = "red" , fg = "blue" , borderwidth = 3 , relief = "raised" )
96107exitb .place (x = 700 , y = 550 )
97108
0 commit comments