tkinter: Copy to clipboard via button
Solution 1:
The problem is that the tkinter UI does not load
Yes it does, but you told it to withdraw()
, so you don't see it.
To do this you need a partial or lambda function, you can't use a normal function call in a command argument. Try this:
import tkinter
r = tkinter.Tk()
age = '''
O.o
giga
'''
gage = 'vrum'
r.title("getherefast")
def gtc(dtxt):
r.clipboard_clear()
r.clipboard_append(dtxt)
tkinter.Button(text='age', command=lambda: gtc(age)).grid(column=1, row=0)
tkinter.Button(text='gage', command=lambda: gtc(gage)).grid(column=2, row=0)
r.mainloop()