from tkinter import *
from tkinter import ttk
import random
root = Tk()
root.geometry("400x200")
def randomNumber(max):
return round(random.random()*max)
class CreateButton:
def __init__(self, name, flag):
self.button = ttk. Button(root, text=name)
self.button.bind("Motion", self.printer)
self.button.pack()
def printer(self,event,flag):
if not flag:
self.button.place(x=randomNumber(400), y=randomNumber(200))
print("q")
obj=CreateButton("ladno", False)
root.mainloop()