Add warns,fix graph len

This commit is contained in:
anqude 2023-02-07 00:19:17 +04:00 committed by GitHub
parent 3ca8c9a75c
commit dbebfb9d0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 76 additions and 50 deletions

View File

@ -107,29 +107,40 @@ Copy = CTkButton(tabview.tab("Line"),text="Copy!",command=copy_click, width = 39
Copy.place(x=122, y=140) Copy.place(x=122, y=140)
def genadiy(): def genadiy():
generate_qr(entry.get(),fg_color,bg_color) state=generate_qr(entry.get(),fg_color,bg_color)
from tkinter import Toplevel,Label from tkinter import Toplevel,Label
from PIL import ImageTk, Image from PIL import ImageTk, Image
window = Toplevel() if state==True:
window.geometry("200x200") window = Toplevel()
window.configure(bg=bg_color) window.geometry("200x200")
window.title("QR") window.configure(bg=bg_color)
window.tk.call('wm', 'iconphoto', window._w, PhotoImage(file='qr.png')) window.title("QR")
bg = ImageTk.PhotoImage(file="qr.png") window.tk.call('wm', 'iconphoto', window._w, PhotoImage(file='qr.png'))
label = Label(window,background=bg_color,highlightbackground=bg_color) bg = ImageTk.PhotoImage(file="qr.png")
label.pack(fill="both", expand=True,anchor='center') label = Label(window,background=bg_color,highlightbackground=bg_color)
counter_loop=[0] label.pack(fill="both", expand=True,anchor='center')
def resize_image(win): counter_loop=[0]
if counter_loop[0]%3==0: def resize_image(win):
image = Image.open("qr.png") if counter_loop[0]%3==0:
size=min(win.width,win.height) image = Image.open("qr.png")
resized = image.resize((size, size)) size=min(win.width,win.height)
image2 = ImageTk.PhotoImage(resized) resized = image.resize((size, size))
window.image2=image2 image2 = ImageTk.PhotoImage(resized)
label.configure(image=image2) window.image2=image2
counter_loop.insert(0,counter_loop[0]+1) label.configure(image=image2)
window.bind("<Configure>", resize_image) counter_loop.insert(0,counter_loop[0]+1)
window.mainloop() window.bind("<Configure>", resize_image)
window.mainloop()
else:
window = Toplevel()
window.configure(bg=bg_color)
window.title("Warning!")
window.tk.call('wm', 'iconphoto', window._w, PhotoImage(file='./ui/warn.png'))
label = Label(window,background=bg_color,highlightbackground=bg_color,text="Too much data to make QR!",foreground=fg_color,font=("Monospace",16))
label.pack(fill="both", expand=True,anchor='center')
window.attributes('-topmost', True)
window.update()
window.mainloop()
genqr = CTkButton(tabview.tab("Line"),text="Generate QR!",command=genadiy,width = 39) genqr = CTkButton(tabview.tab("Line"),text="Generate QR!",command=genadiy,width = 39)
genqr.place(x=175, y=140) genqr.place(x=175, y=140)
@ -163,33 +174,44 @@ def gena():
n=int(len_entry.get()) n=int(len_entry.get())
yn=int(y_entry.get()) yn=int(y_entry.get())
xn=int(x_entry.get()) xn=int(x_entry.get())
from tkinter import Canvas, Toplevel from tkinter import Canvas, Toplevel, Label
root = Toplevel() if not ( n<=1 or n>xn*yn):
root.configure(background="#242424") root = Toplevel()
root.title("Graph") root.configure(background="#242424")
root.geometry("200x200") root.title("Graph")
root.tk.call('wm', 'iconphoto', root._w, PhotoImage(file='./ui/graph.png')) root.geometry("200x200")
resx,resy=400,400 root.tk.call('wm', 'iconphoto', root._w, PhotoImage(file='./ui/graph.png'))
canvas = Canvas(root,background=bg_color,highlightbackground=bg_color) resx,resy=400,400
canvas.pack(fill="both", expand=True) canvas = Canvas(root,background=bg_color,highlightbackground=bg_color)
a=ggraph(n, xn, yn) canvas.pack(fill="both", expand=True)
Xcoordinates,Ycoordinates,Xnull_coordinates,Ynull_coordinates=anonim(n,xn,yn,a,resx,resy) a=ggraph(n, xn, yn)
def draw(n,xn,yn,Xcoordinates,Ycoordinates,Xnull_coordinates,Ynull_coordinates): Xcoordinates,Ycoordinates,Xnull_coordinates,Ynull_coordinates=anonim(n,xn,yn,a,resx,resy)
for i in range (xn): #кол-во линий def draw(n,xn,yn,Xcoordinates,Ycoordinates,Xnull_coordinates,Ynull_coordinates):
for j in range(yn): #кол-во строк for i in range (xn): #кол-во линий
canvas.create_oval(Xnull_coordinates[i]-3,Ynull_coordinates[j]-3,Xnull_coordinates[i]+3,Ynull_coordinates[j]+3,width=7,fill=fg_color,outline="#565b5e") for j in range(yn): #кол-во строк
canvas.create_oval(Xnull_coordinates[i]-3,Ynull_coordinates[j]-3,Xnull_coordinates[i]+3,Ynull_coordinates[j]+3,width=7,fill=fg_color,outline="#565b5e")
for i in range (n-1): #Кол-во точек -1 тк это линии лол
canvas.create_line(Xcoordinates[i], Ycoordinates[i], Xcoordinates[i+1], Ycoordinates[i+1],width=7,arrow="last",fill=fg_color) for i in range (n-1): #Кол-во точек -1 тк это линии лол
draw(n,xn,yn,Xcoordinates,Ycoordinates,Xnull_coordinates,Ynull_coordinates) canvas.create_line(Xcoordinates[i], Ycoordinates[i], Xcoordinates[i+1], Ycoordinates[i+1],width=7,arrow="last",fill=fg_color)
def sizable(event): draw(n,xn,yn,Xcoordinates,Ycoordinates,Xnull_coordinates,Ynull_coordinates)
resx,resy = event.width, event.height def sizable(event):
canvas.delete("all") resx,resy = event.width, event.height
Xcoordinates,Ycoordinates,Xnull_coordinates,Ynull_coordinates=anonim(n,xn,yn,a,resx,resy) canvas.delete("all")
draw(n, xn, yn,Xcoordinates,Ycoordinates,Xnull_coordinates,Ynull_coordinates) Xcoordinates,Ycoordinates,Xnull_coordinates,Ynull_coordinates=anonim(n,xn,yn,a,resx,resy)
draw(n, xn, yn,Xcoordinates,Ycoordinates,Xnull_coordinates,Ynull_coordinates)
canvas.bind('<Configure>', sizable)
root.mainloop() canvas.bind('<Configure>', sizable)
root.mainloop()
else:
root = Toplevel()
root.configure(bg=bg_color)
root.title("Warning!")
root.tk.call('wm', 'iconphoto', root._w, PhotoImage(file='./ui/warn.png'))
label = Label(root,background=bg_color,highlightbackground=bg_color,text="Incorrect length!",foreground=fg_color,font=("Monospace",16))
label.pack(fill="both", expand=True,anchor='center')
root.attributes('-topmost', True)
root.update()
root.mainloop()
generate_graph=CTkButton(tabview.tab("Graph"),command=gena, text="Generate!",width=320) generate_graph=CTkButton(tabview.tab("Graph"),command=gena, text="Generate!",width=320)

View File

@ -8,7 +8,7 @@ def graph(x,y): #Создаём двумерный массив, заполне
return a return a
def ggraph(n,xn,yn): def ggraph(n,xn,yn):
m = 1 m = 0
xym = [xn,yn] xym = [xn,yn]
b = graph(xn, yn) b = graph(xn, yn)
av = [[-1,-1]] av = [[-1,-1]]

View File

@ -2,9 +2,13 @@ import qrcode
def generate_qr(password,fg_color,bg_color): def generate_qr(password,fg_color,bg_color):
qr = qrcode.QRCode() qr = qrcode.QRCode()
qr.add_data('password: '+password) qr.add_data('password: '+password)
qr.make(fit=True) try:
qr.make(fit=True)
except:
return False
img = qr.make_image(fill_color=fg_color, back_color=bg_color) img = qr.make_image(fill_color=fg_color, back_color=bg_color)
img.save("qr.png") img.save("qr.png")
return True
def generate_qr_text(password): def generate_qr_text(password):
qr = qrcode.QRCode() qr = qrcode.QRCode()

BIN
ui/warn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 373 B