1
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.

tornike
  • 27
  • 4
  • 1
    The line `command=save(emty_str.get())` will execute `save()` immediately. It should be `command=lambda: save(emty_str.get())` instead. – acw1668 Apr 09 '21 at 09:29
  • Yes, it does. but i have another problem: I want to erase everythin in image1 after saving. Any ideas ? i could not do that with image1.paste(). – tornike Apr 09 '21 at 12:20
  • I just want after saving image1 to be emty, to be clear – tornike Apr 09 '21 at 12:28
  • You can use the `rectangle()` function to fill the entire image to act like clear. – acw1668 Apr 09 '21 at 12:47

0 Answers0