'How to display button (Tkinter) red or green when we got 0 or 1 data?
I have project for read and show data from text file.
import os
import io
work_dir = "C:\\Users\\xxxxx\\labels"
for index in range(191, 221):
name = "CushionOK_{index}.txt".format(index=index)
path = os.path.join(work_dir, name)
with io.open(path, mode="r", encoding="utf-8") as fd:
content = fd.read(1)
int(content)
if int(content) == 1:
print("OK")
else:
print("NG")
From above code is show only OK or NG but I'd like to show button (Tkinter) red or green too.
For red(NG)
import tkinter as tk
root2 = tk.Tk()
tk.Button(root2,text='NG',font=('Helvetica bold',150), bg = "red").place(
x=250, y= 250, w= 350, h= 350, anchor='center')
tk.Button(root2,text='Sign in', bg = "grey").place(x=250, y= 450,w= 60, h= 30,
anchor='center')
root2.geometry("500x500")
root2.mainloop()
For Red(NG) button will push sign in button for apply private code (Ex.1234) to show other folder.
and Green button(OK).
import tkinter as tk
root1 = tk.Tk()
tk.Button(root1,text='OK',font=('Helvetica bold',150), bg = "green").place(
x=250, y= 250, w= 350, h= 350, anchor='center')
tk.Button(root1,text='Confirm', bg = "grey").place(
x=250, y= 450,w= 60, h= 30, anchor='center')
root1.geometry("500x500")
root1.mainloop()
For Green button will push confirm button for close it.
I'd like to show button (Tkinter) red or green for represent 0 (red button) or 1 (green button). Now I can create separate code but I'd like to add all code together.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
