-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
136 lines (97 loc) · 4.09 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from tkinter import *
import socket
from tkinter import filedialog
from tkinter import messagebox
import os
root=Tk()
root.title("Share Me")
root.geometry("450x560+500+200")
root.configure(bg="#f4fdfe")
root.resizable(False,False)
def Send():
window=Toplevel(root)
window.title("Send")
window.geometry('450x560+500+200')
window.configure(bg="#f4fdfe")
window.resizable(False,False)
def select_file():
global filename
filename=filedialog.askopenfilename(initialdir=os.getcwd(),title='Select Image File',filetype=(('file_type','*.txt'),("all files","*.*")))
def sender():
s=socket.socket()
host=socket.gethostname()
port=8080
s.bind((host,port))
s.listen(1)
print(host)
print("waiting for any incoming connections.......")
conn,addr=s.accept()
file=open(filename,'rb')
file_data=file.read(1024)
conn.send(file_data)
print("Data has been transmitted Successfully...")
#icon
image_icon1=PhotoImage(file="Image/send.png")
window.iconphoto(False,image_icon1)
Sbackground=PhotoImage(file="Image/sender.png")
Label(window,image=Sbackground).place(x=-2,y=0)
Mbackground=PhotoImage(file="Image/id.png")
Label(window,image=Mbackground,bg="#f4fdfe").place(x=100,y=260)
host=socket.gethostname()
Label(window,text=f'ID: {host}',bg='white',fg='black').place(x=140,y=290)
Button(window,text="+ Select File",width=10,height=1,font='arial 14 bold',bg="#fff",fg="#000",command=select_file).place(x=160,y=150)
Button(window,text="SEND",width=8,height=1,font='arial 14 bold',fg="#fff",bg="#000",command=sender).place(x=300,y=150)
window.mainloop()
def Receive():
main=Toplevel(root)
main.title("Receive")
main.geometry('450x560+500+200')
main.configure(bg="#f4fdfe")
main.resizable(False,False)
def receiver():
ID=SenderID.get()
filename1=incoming_file.get()
s=socket.socket()
port=8080
s.connect((ID,port))
file=open(filename1,'wb')
file_data=s.recv(1024)
file.write(file_data)
file.close()
print("File has been received Successfully")
#icon
image_icon1=PhotoImage(file="Image/receive.png")
main.iconphoto(False,image_icon1)
Hbackgroubnd=PhotoImage(file="Image/receiver.png")
Label(main,image=Hbackgroubnd).place(x=-2,y=0)
logo=PhotoImage(file='Image/profile.png')
Label(main,image=logo,bg="#f4fdfe").place(x=100,y=250)
Label(main,text="Receive",font=('arial',20),bg="#f4fdfe").place(x=100,y=280)
Label(main,text='Imput Sender id',font=('arial',10,'bold'),bg="#f4fdfe").place(x=20,y=340)
SenderID=Entry(main,width=25,fg="black",border=2,bg='white',font=('arial',15))
SenderID.place(x=20,y=370)
SenderID.focus()
Label(main,text='Filename for the incoming file:',font=('arial',10,'bold'),bg="#f4fdfe").place(x=20,y=420)
incoming_file=Entry(main,width=25,fg="black",border=2,bg='white',font=('arial',15))
incoming_file.place(x=20,y=450)
imageicon=PhotoImage(file="Image/arrow.png")
rr=Button(main,text="Receive",compound=LEFT,image=imageicon,width=130,bg="#39c790",font="arial 14 bold",command=receiver)
rr.place(x=20,y=500)
main.mainloop()
#icon
image_icon=PhotoImage(file="Image/icon.png")
root.iconphoto(False,image_icon)
Label(root,text="File Transfer",font=('Acumin Variable Concept',20,'bold'),bg="#f4fdfe").place(x=0,y=30)
Frame(root,width=400,height=2,bg="#f3f5f6").place(x=25,y=80)
send_image=PhotoImage(file="Image/send.png")
send=Button(root,image=send_image,bg="#f4fdfe",bd=0,command=Send)
send.place(x=50,y=100)
receive_image=PhotoImage(file="Image/receive.png")
receive=Button(root,image=receive_image,bg="#f4fdfe",bd=0,command=Receive)
receive.place(x=300,y=100)
#Label
Label(root,text="Send",font=('Acumin Variable Concept',17,'bold'),bg="#f4fdfe").place(x=65,y=200)
Label(root,text="Reveive",font=('Acumin Variable Concept',17,'bold'),bg="#f4fdfe").place(x=300,y=200)
background=PhotoImage(file="Image/background.png")
Label(root,image=background).place(x=-2,y=323)
root.mainloop()