前提・実現したいこと
STARTボタンが押された状態(緑色)でSTOPボタンを押すと、STARTボタンが灰色になり、同時にSTOPボタンが赤色になる動作をさせたいです。
該当のソースコード
#!/usr/bin/env python # -*- coding: utf8 -*- import Tkinter as tk #------------------------------ #コールバック関数群 #------------------------------ def callback1(event):#それぞれのボタンを押さなければ色が変わらない if event.widget["bg"] == "LightCyan4": event.widget["bg"] = "lime green" red = "cyan" else: event.widget["bg"] = "LightCyan4" def callback2(event): if event.widget["bg"] == "LightCyan4": event.widget["bg"] = "red" red = "cyan" else: event.widget["bg"] = "LightCyan4" #HOME画面生成 root = tk.Tk() root.title("HOME") #STARTボタン Button = tk.Button(root, height = "5", width = "20", text = "START", font = ("",15,"bold"), bg = "LightCyan4") Button.pack(side="left") Button.bind("<1>",callback1) #STOPボタン Button = tk.Button(root, height = "5", width = "20", text = "STOP", font = ("",15,"bold"), bg = "LightCyan4") Button.pack(side="left") Button.bind("<1>",callback2) root.mainloop()
補足情報(FW/ツールのバージョンなど)
python2.7
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/07 05:17