-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinked_List_UI.py
More file actions
285 lines (242 loc) · 6.92 KB
/
Linked_List_UI.py
File metadata and controls
285 lines (242 loc) · 6.92 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
from tkinter import *
import tkinter as tk
from tkinter import ttk
from playsound import playsound
import multiprocessing
global taili
global taily
taili = 4
taily = 0
global labels
labels = []
def create_label(val, taili, taily, nextID):
count = len(root.winfo_children())
label = Label(root, text=f"Label #{val} \n#{nextID}")
label.grid(row=taili, column=taily)
labels.append(label)
def removing_label(tali, taly):
label = Label(root, text="AAAAAAAAAAAAAAAA\nA", bg="#9cacff",fg="#9cacff")
label.grid(row=taili, column=taily)
class Node:
def __init__(self, data=None):
self.data = data
self.next = None
class SLinkedList:
def __init__(self):
self.head = None
def Atbegining(self, data_in):
NewNode = Node(data_in)
obj_id = id(self.head)
NewNode.next = self.head
self.head = NewNode
llist.LListprint()
# Function to add newnode
def AtEnd(self, newdata):
NewNode = Node(newdata)
if self.head is None:
self.head = NewNode
llist.LListprint()
return
laste = self.head
while(laste.next):
laste = laste.next
laste.next=NewNode
llist.LListprint()
# Function to add node
def Inbetween(self,middle_node_num,newdata):
printval = self.head
while(middle_node_num > 1):
printval = printval.next
middle_node_num -= 1
if printval is None:
return
NewNode = Node(newdata)
NewNode.next = printval.next
printval.next = NewNode
self.LListprint()
# Function to remove node
def RemoveNode(self, RemoveNode):
HeadVal = self.head
if (HeadVal is not None):
if (RemoveNode == 1):
self.head = HeadVal.next
HeadVal = None
return
while(RemoveNode > 2):
HeadVal = HeadVal.next
RemoveNode -= 1
if HeadVal is None:
return
prev = HeadVal
HeadVal = HeadVal.next
prev.next = HeadVal.next
HeadVal = None
llist.LListprint()
def LListprint(self):
global taili
global taily
taili = 4
taily = 0
printval = self.head
while (printval):
obj_id = id(printval.next)
if taily == 4:
taily = 0
taili += 2
BlankLabel = Label(root, text="", bg="#9cacff", fg="#9cacff")
BlankLabel.grid(row=taili - 1, column=0)
create_label(printval.data, taili, taily, obj_id)
taily += 1
print(printval.data)
printval = printval.next
root = Tk()
root.configure(bg="#9cacff")
root.title("Linked List")
#CreateList
def CreateList_Func():
global llist
llist = SLinkedList()
status = Tk()
status.title("Status")
statusLabel = Label(status, text="\nLinked List is created!\n")
statusLabel.grid(row=0,column=0)
#AddNode
def AddNodeBeg_Func():
valuePage = Tk()
valuePage.title("Enter Value")
valuePage.configure(bg="red")
value = Entry(valuePage, width=20, bg="black", fg="white", borderwidth=5)
value.grid(row=0, column=0)
AddValue_But = Button(valuePage, text="Add Value",
padx=53, pady=10,
bg="#ff5733",
command=lambda: llist.Atbegining(value.get()))
print(value.get())
AddValue_But.grid(row=1, column=0)
#AddNewNode
def AddNodeEnd_Func():
valuePage = Tk()
valuePage.title("Enter Value")
valuePage.configure(bg="red")
value = Entry(valuePage, width=20, bg="black", fg="white", borderwidth=5)
value.grid(row=0, column=0)
AddValue_But = Button(valuePage, text="Add Value",
padx=53, pady=10,
bg="#ff5733",
command=lambda: llist.AtEnd(value.get()))
print(value.get())
AddValue_But.grid(row=1, column=0)
#RemoveNode
def RemoveNode_Func():
valuePage = Tk()
valuePage.title("Enter the Node")
valuePage.configure(bg="red")
nodeNum = Entry(valuePage, width=20, bg="black", fg="white", borderwidth=5)
nodeNum.grid(row=0, column=1)
AddValue1_But = Button(valuePage, text="Remove this node",
padx=53, pady=10,
bg="#ff5733",
command=lambda: llist.RemoveNode(int(nodeNum.get())))
AddValue1_But.grid(row=1, column=0)
#InsertNode
def InsertNode_Func():
valuePage = Tk()
valuePage.title("Enter Value and Node number")
valuePage.configure(bg="red")
value = Entry(valuePage, width=20, bg="black", fg="white", borderwidth=5)
value.grid(row=0, column=0)
nodeNum = Entry(valuePage, width=20, bg="black", fg="white", borderwidth=5)
nodeNum.grid(row=0, column=1)
AddValue1_But = Button(valuePage, text="Check Values",
padx=53, pady=10,
bg="#ff5733",
command=lambda: llist.Inbetween(int(nodeNum.get()),value.get()))
AddValue1_But.grid(row=1, column=0)
#RemoveAll
def RemoveAll_Func():
global taili
global taily
taili = 4
taily = 0
count = 0
current = llist.head
while (llist.head != None):
if(taily == 4):
taily = 0
taili += 1
current = llist.head
llist.head = llist.head.next
removing_label(taili, taily)
taily += 1
count +=1
current = None
#Multiprocessing
def MultiProc_Func():
p = multiprocessing.Process(target=PlaySound_Func)
p.start()
sound = Tk()
sound_But = Button(sound, text="Press to stop",
padx=30, pady=3,
bg="#ee75ff",
command=lambda: [p.terminate(), sound.destroy()])
sound_But.grid(row=0, column=0)
#playsound
def PlaySound_Func():
playsound('future.mp3')
#Exit
def Exit_Func():
root.destroy()
#Create List
CreateList_But = Button(root, text="Create List",
padx=55, pady=10,
bg="#ffa500",
command=CreateList_Func)
CreateList_But.grid(row=0, column=0)
#Add Node
AddNodeEnd_But = Button(root, text="Add Node\n At the End",
padx=52, pady=3,
bg="#808080",
command=AddNodeEnd_Func)
AddNodeEnd_But.grid(row=0, column=1)
#Add New Node
AddNodeBeg_But = Button(root, text="Add Node\n At the Beginning",
padx=30, pady=3,
bg="#ee75ff",
command=AddNodeBeg_Func)
AddNodeBeg_But.grid(row=0, column=2)
#Reove Node
RemoveNode_But = Button(root, text="Remove Node",
padx=40, pady=10,
bg="#8475ff",
command=RemoveNode_Func)
RemoveNode_But.grid(row=0, column=3)
#Insert Node
InsertNode_But = Button(root, text="Insert Node",
padx=52, pady=10,
bg="#33c7ff",
command=InsertNode_Func)
InsertNode_But.grid(row=1, column=0)
#Remove All
RemoveAll_But = Button(root, text="Remove All",
padx=49, pady=10,
bg="#6bff33",
command=RemoveAll_Func)
RemoveAll_But.grid(row=1, column=1)
#Playsound
Playsound_But = Button(root, text="Play Music",
padx=49, pady=10,
bg="#6bff33",
command=MultiProc_Func)
Playsound_But.grid(row=1, column=2)
#Exit
Exit_But = Button(root, text="Exit",
padx=73, pady=10,
bg="#ff5733",
command=Exit_Func)
Exit_But.grid(row=1, column=3)
#separator
BlankLabel = Label(root, text="", bg="#9cacff", fg="#9cacff")
BlankLabel.grid(row=2, column=0)
sep2 = ttk.Separator(root, orient="horizontal")
sep2.grid(row=3, column=0, columnspan=4, ipadx=360)
root.mainloop()