Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- class Node:
- def __init__(self, value=None, next=None):
- self.cargo = value
- self.next = next
- def __str__(self):
- out = str(self.cargo)
- return out
- class List:
- def __init__(self):
- self.head = None
- self.end = None
- self.length = 0
- def __str__(self):
- if self.head is not None:
- current = self.head
- out = 'List: [ ' + str(current.cargo) + ' '
- while current.next is not None:
- current = current.next
- out += str(current.cargo) + ' '
- return out + ']'
- else:
- out = 'List is clear'
- return out
- def add(self, x):
- self.length += 1
- if self.head is None:
- self.end = self.head = Node(x, None)
- else:
- self.end.next = self.end = Node(x, None)
- def clear(self):
- self.__init__()
- def remove(self, i):
- if self.head is None:
- return
- curr = self.head
- count = 0
- if i == 0:
- self.head = self.head.next
- self.length -= 1
- return
- while curr is not None:
- if count == i:
- if curr.next is None:
- self.end = curr
- old.next = curr.next
- self.length -= 1
- break
- old = curr
- curr = curr.next
- count += 1
- def search(self):
- while True:
- num = 0
- coun = 0
- curr = self.head
- deleted = False
- found = False
- for i in range(0, self.length):
- if curr.cargo % 4 == 0:
- found = True
- coun += 1
- num += coun
- coun = 0
- else:
- coun += 1
- curr = curr.next
- if found is True:
- self.remove(num-1)
- deleted = True
- if deleted is False:
- break
- L = List()
- root = Tk()
- root.title("Laba 1")
- root.geometry("640x360+0+0")
- root.resizable(False, False)
- text = Text(wrap=WORD)
- text.place(x=50, y=250, height=66, width=399)
- txt = Entry()
- txt.place(x=50, y=100, height=33, width=133)
- def new():
- s = txt.get()
- s = int(s)
- L.add(s)
- txt.delete(0, END)
- add = Button(root, text="Add", command=new)
- add.place(x=50, y=50, height=33, width=133)
- def output():
- text.delete(1.0, END)
- s = L.__str__()
- text.insert(1.0, s)
- def remove():
- L.search()
- if L.head is not None:
- add.config(state=DISABLED)
- show = Button(root, text="Print", command=output)
- show.place(x=200, y=100, height=33, width=133)
- replace = Button(root, text="Delete", command=remove)
- replace.place(x=200, y=50, height=33, width=133)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement