1
+
2
+ # imported necessary library
1
3
from tkinter import *
2
4
from tkinter import messagebox
3
5
import tkinter .messagebox as mbox
4
6
import tkinter as tk
5
7
6
-
8
+ # created main window
7
9
root = Tk ()
8
10
root .title ("Virtual Copy Paste" )
9
11
root .geometry ('1000x700' )
10
12
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 ------------------
16
14
def des_f1 ():
17
15
f1 .destroy ()
18
16
19
-
17
+ # frame 1 created which is the main window
20
18
f1 = Frame (root , height = 700 , width = 1000 )
21
19
f1 .propagate (0 )
22
20
f1 .pack (side = 'top' )
23
21
22
+ # this is for adding image in the main window
24
23
c = Canvas (f1 , width = 1000 , height = 700 )
25
24
c .pack ()
26
25
p1 = PhotoImage (file = 'Images/copy_paste.gif' )
27
26
c .create_image (0 , 100 , image = p1 , anchor = NW )
28
27
28
+ # for starting label
29
29
start1 = Label (f1 , text = 'VIRTUAL Copy Paste' , font = ("Arial" , 50 ), fg = "magenta" , underline = 0 )
30
30
start1 .place (x = 150 , y = 10 )
31
31
32
+ # created a START button
32
33
startb = Button (f1 , text = "START" ,command = des_f1 ,font = ("Arial" , 30 ), bg = "light green" , fg = "blue" , borderwidth = 3 , relief = "raised" )
33
34
startb .place (x = 180 , y = 550 )
34
35
# ------------------------------------------------------
35
36
36
37
# frame 2 ---------------------------------------------
38
+ # created global variable s
37
39
s = ""
38
40
41
+ # function for clearing the default text from text1 when put cursor on it
39
42
firstclick1 = True
40
43
def on_text_enter_click (event ):
41
44
"""function that gets called whenever entry1 is clicked"""
@@ -44,16 +47,19 @@ def on_text_enter_click(event):
44
47
firstclick1 = False
45
48
text1 .delete ('1.0' , "end" ) # delete all the text in the entry
46
49
50
+ # function for copying the text
47
51
def copy_text ():
48
52
global s
49
53
s = s + text1 .get ("1.0" , "end-1c" )
50
54
55
+ # function for seeing the copied text
51
56
def see_text ():
52
57
if (s == "" ):
53
58
mbox .showerror ("Error" , "You haven't copied anything!" )
54
59
else :
55
60
mbox .showinfo ("Copied Text" , "COPIED TEXT :\n \n " + s )
56
61
62
+ # function for pasting the text
57
63
def paste_text ():
58
64
global s
59
65
if (s == "" ):
@@ -63,35 +69,40 @@ def paste_text():
63
69
text2 .insert (END , s )
64
70
s = ""
65
71
66
-
72
+ # created frame 2
67
73
f2 = Frame (root , height = 700 , width = 1000 )
68
74
f2 .propagate (0 )
69
75
f2 .pack (side = 'top' )
70
76
77
+ # created first textarea
71
78
text1 = tk .Text (f2 , height = 20 , width = 35 , font = ("Arial" , 15 ), bg = "light yellow" , fg = "brown" ,borderwidth = 3 , relief = "solid" )
72
79
text1 .insert (END , 'Enter any text here and Copy it...' ) # default line in text area, can be cleared when touched
73
80
text1 .bind ('<FocusIn>' , on_text_enter_click )
74
81
text1 .place (x = 50 , y = 20 )
75
82
83
+ # created second textarea
76
84
text2 = tk .Text (f2 , height = 20 , width = 35 , font = ("Arial" , 15 ), bg = "light yellow" , fg = "brown" ,borderwidth = 3 , relief = "solid" )
77
85
text2 .insert (END , 'Paste the copied text here...' ) # default line in text area, can be cleared when touched
78
86
text2 .place (x = 550 , y = 20 )
79
87
80
-
88
+ # created COPY button
81
89
copyb = Button (f2 , text = "COPY" ,command = copy_text ,font = ("Arial" , 30 ), bg = "light green" , fg = "blue" , borderwidth = 3 , relief = "raised" )
82
90
copyb .place (x = 100 , y = 550 )
83
91
92
+ # Created SEE button
84
93
seeb = Button (f2 , text = "SEE" ,command = see_text ,font = ("Arial" , 30 ), bg = "light green" , fg = "blue" , borderwidth = 3 , relief = "raised" )
85
94
seeb .place (x = 300 , y = 550 )
86
95
96
+ # created a PASTE button
87
97
pasteb = Button (f2 , text = "PASTE" ,command = paste_text ,font = ("Arial" , 30 ), bg = "light green" , fg = "blue" , borderwidth = 3 , relief = "raised" )
88
98
pasteb .place (x = 480 , y = 550 )
89
99
100
+ # function for exiting
90
101
def exit_win ():
91
102
if messagebox .askokcancel ("Exit" , "Do you want to exit?" ):
92
103
root .destroy ()
93
104
94
-
105
+ # created a exit button
95
106
exitb = Button (root , text = "EXIT" ,command = exit_win ,font = ("Arial" , 30 ), bg = "red" , fg = "blue" , borderwidth = 3 , relief = "raised" )
96
107
exitb .place (x = 700 , y = 550 )
97
108
0 commit comments