好吧,我已经更新了我的代码,现在,我唯一遇到的问题是,我想在用户单击“911”时关闭窗口并且我尝试使用 while 循环,但问题是我想不出一个好的将 911 按钮设置为 = win.close 的方法,另一个问题是,我想更改用户单击的最后一个按钮的按钮颜色,当我单击它时更改了其中一个按钮的颜色,但是如果我单击另一个按钮 上一个按钮不会变回主颜色:S 有什么可以帮助解决我的问题的吗?
# button.py
from graphics import *
from dieview import DieView
from button import Button
win = GraphWin("Phone", 160,160)
win.setBackground("gray")
m = Button (win, Point(30,20),10,10,"1")
quitButton= Button(win, Point(60,20), 10, 10, "2")
quitButton.label.setFill('black')
quitButton.rect.setWidth(1)
quitButton.active=True
quitButton1 = Button(win, Point(30,20), 10, 10, "1")
quitButton1.label.setFill('black')
quitButton1.rect.setWidth(1)
quitButton1.active=True
quitButton2 = Button(win, Point(90,20), 10, 10, "3")
quitButton2.label.setFill('black')
quitButton2.rect.setWidth(1)
quitButton2.active=True
quitButton3 = Button(win, Point(30,50), 10, 10, "4")
quitButton3.label.setFill('black')
quitButton3.rect.setWidth(1)
quitButton3.active = True
quitButton4 = Button(win, Point(60,50), 10, 10, "5")
quitButton4.label.setFill('black')
quitButton4.rect.setWidth(1)
quitButton4.active=True
quitButton5 = Button(win, Point(90,50), 10, 10, "6")
quitButton5.label.setFill('black')
quitButton5.rect.setWidth(1)
quitButton5.active=True
quitButton6 = Button(win, Point(30,80), 10, 10, "7")
quitButton6.label.setFill('black')
quitButton6.rect.setWidth(1)
quitButton6.active=True
quitButton7 = Button(win, Point(60,80), 10, 10, "8")
quitButton7.label.setFill('black')
quitButton7.rect.setWidth(1)
quitButton7.active=True
quitButton8 = Button(win, Point(90,80), 10, 10, "9")
quitButton8.label.setFill('black')
quitButton8.rect.setWidth(1)
quitButton8.active=True
quitButton0 = Button(win,Point(90,110),20,10,"quit")
quitButton0.label.setFill("red")
quitButton0.rect.setWidth(1)
quitButton0.active=True
q=Circle(Point(90,110),10)
q.setFill("gray")
q.draw(win)
Text(Point(90,110),"quit").draw(win)
value=DieView(win,Point(30,20),10)
value8=DieView(win,Point(90,80),10)
c = Circle(Point(30,20),10)
c.setFill("lightgray")
c.draw(win)
Text(Point(30,20), "1").draw(win)
c1 = Circle(Point(60,20),10)
c1.setFill("lightgray")
c1.draw(win)
Text(Point(60,20), "2").draw(win)
c2 = Circle(Point(90,20),10)
c2.setFill("lightgray")
c2.draw(win)
Text(Point(90,20),"3").draw(win)
c3 = Circle(Point(30,50),10)
c3.setFill("lightgray")
c3.draw(win)
c4 = Circle(Point(60,50),10)
c4.setFill("lightgray")
c4.draw(win)
Text(Point(30,50), "4").draw(win)
c5 = Circle(Point(90,50),10)
c5.setFill("lightgray")
c5.draw(win)
Text(Point(60,50), "5").draw(win)
c6 = Circle(Point(30,80),10)
c6.setFill("lightgray")
c6.draw(win)
Text(Point(90,50), "6").draw(win)
c7 = Circle(Point(60,80),10)
c7.setFill("lightgray")
c7.draw(win)
Text(Point(30,80), "7").draw(win)
c8 = Circle(Point(90,80),10)
c8.setFill("lightgray")
c8.draw(win)
Text(Point(60,80), "8").draw(win)
Text(Point(90,80), "9").draw(win)
listclick=[quitButton,quitButton1]
pt = win.getMouse()
while not quitButton0.clicked(pt):
if quitButton.clicked(pt):
print("2")
c1.setFill("red")
elif quitButton1.clicked(pt):
print("1")
elif quitButton2.clicked(pt):
quitButton.active=True
print("3")
elif quitButton3.clicked(pt):
quitButton3.active = True
print("4")
elif quitButton4.clicked(pt):
quitButton4.active = True
print("5")
elif quitButton5.clicked(pt):
quitButton5.active = True
print("6")
elif quitButton6.clicked(pt):
quitButton6.active = True
print("7")
elif quitButton7.clicked(pt):
quitButton7.active = True
print("8")
elif quitButton8.clicked(pt):
quitButton8.active=True
print("9")
pt = win.getMouse()
quitButton0=win.close()