from PIL import ImageTk, Image, ImageDraw
import PIL
from tkinter import *
import random
width = 200
height = 200
center = height//2
white = (255, 255, 255)
green = (0,128,0)
def generate_random():
minimum = pow(10, 9 - 1)
maximum = max = pow(10, 9) - 1
randomnumber = random.randint(minimum, maximum)
return randomnumber
def save(char):
filename = f"Alphabet/{char}{generate_random()}.png"
image1.save(filename)
cv.delete('all')
def paint(event):
x1, y1 = (event.x - 1), (event.y - 1)
x2, y2 = (event.x + 1), (event.y + 1)
cv.create_line(x1, y1, x2, y2, fill="white",width=5)
draw.line([x1, y1, x2, y2],fill="white",width=5)
root = Tk()
cv = Canvas(root, width=width, height=height, bg='black')
cv.pack()
image1 = PIL.Image.new("RGB", (width, height), (0,0,0))
draw = ImageDraw.Draw(image1)
values = {"ა": "ა",
"ბ": "ბ",
"გ": "გ",
"დ": "დ",
"ე": "ე"}
emty_str=StringVar()
for (text, value) in values.items():
Radiobutton(root, text=text, variable=emty_str,
value=value).pack(side=TOP, ipady=5)
cv.pack(expand=YES, fill=BOTH)
cv.bind("<B1-Motion>", paint)
print(X)
print(emty_str)
button=Button(text="save",command=save(emty_str.get()))
button.pack()
root.mainloop()
I want to get The image with name of radiobutton value and random number combined but emty_str returns PY_VAR0 so any help? Also The Save function is activated before i click on save button. Generly, i want to make program that paints on canvas and returns the image with name of radiobutton value and random number combined.