1

I am looking for the way I can use x value within Tkinter widget. I couldn't find an appropriate answer from the web. Any advice is appreciated. Thanks


regarding, confirm, it returns x and print(x) works.

from pyautogui import *    
def test():
    global x
    x = confirm(buttons=['z2037', 'z2039'])        
test()
print(x)

from pyautogui import *
from tkinter import *
root = Tk()    
def test():
    global x
    x = confirm(buttons=['Z2 037', 'Z2 039'])    

b = Button(root, text='KLO', padx=50, pady=50, command=test)
b.pack()

root.mainloop()
print(x)

If I add print(x) above root.mainloop(), Python throws an error, saying that name 'x' is not defined although it's global. If I add print(x) below root.mainloop(), it works.

But, I want to use x value(Z2 037, or Z2 039) inside tkinter widget. Is there any way to do that?

BBiYak
  • 29
  • 5

1 Answers1

0

okay from what I gathered you want it to print every time one of the buttons are pushed (i may be wrong)

this is what i managed to get

from pyautogui import *
from tkinter import *
root = Tk()
root.geometry('700x600+500+100')


def test():
    x = confirm(buttons=['Z2 037', 'Z2 039'])

    print(x)

b = Button(root, text='KLO', padx=50, pady=50, command=test)
b.pack()


root.mainloop()

Output:

Z2 039
Z2 037
  • Thank you @Alasdair, but I wanted to use x value as a global(outside of the function), which is either Z2 037 or Z2 039 – BBiYak Jul 02 '20 at 07:19