python Tkinter按钮上文字变化怎么弄
#!/usr/bin/python2.7 #! -*- coding: utf-8 -*- import Tkinter root = Tkinter.Tk() root.title("My tools") root.geometry('300x300+300+300') def on_off(): if btonoff['text'] == 'on': btonoff['text'] = 'off' else: btonoff['text'] = 'on' btonoff = Tkinter.Button(root, text="on", command=on_off) btonoff.place(x=100, y=160, width=100, height=40) root.mainloop()
#!/usr/bin/python2.7
#! -*- coding: utf-8 -*-
import
Tkinter
root
=
Tkinter.Tk()
root.title(
"My tools"
)
root.geometry(
'300x300+300+300'
)
def
on_off():
if
btonoff[
'text'
]
=
=
'on'
:
btonoff[
'text'
]
=
'off'
else
:
btonoff[
'text'
]
=
'on'
btonoff
=
Tkinter.Button(root, text
=
"on"
, command
=
on_off)
btonoff.place(x
=
100
, y
=
160
, width
=
100
, height
=
40
)
root.mainloop()