SFR
Cadet 4th Year
- Registriert
- Feb. 2014
- Beiträge
- 126
Hi,
bin neu bei Python und probiere ein paar Sachen aus fuer eine GUI.
Nun wuerde ich gerne den button_a "blinken" lassen. Jedoch sobald ich die while True Schleife aktiviere, wird mir gar keine GUI mehr angezeigt. Wie muss ich die Schleife in das Programm schreiben, so dass mir meine GUI noch angezeigt wird und mein button_a blinkt?
Vielleicht ist das eine dumme Frage, aber ich stehe im Moment wirklich auf dem Schlauch.
Viele Gruesse
SFR
bin neu bei Python und probiere ein paar Sachen aus fuer eine GUI.
Python:
from tkinter import *
import time
# creating basic window
window = Tk()
window.geometry("500x375") # size of the window width:- 500, height:- 375
window.resizable(0, 0) # this prevents from resizing the window
window.title("Keyboard")
################################### functions ######################################
# 'btn_click' function continuously updates the input field whenever you enters a number
def btn_click(item):
global expression
expression = expression + str(item)
input_text.set(expression)
# 'btn_clear' function clears the input field
def btn_clear():
global expression
expression = ""
input_text.set("")
expression = ""
# 'StringVar()' is used to get the instance of input field
input_text = StringVar()
# creating a frame for the input field
input_frame = Frame(window, width = 312, height = 50, bd = 0, highlightbackground = "black", highlightcolor = "black", highlightthickness = 1)
input_frame.pack(side = TOP)
# creating a input field inside the 'Frame'
input_field = Entry(input_frame, font = ('arial', 18, 'bold'), textvariable = input_text, width = 50, bg = "#eee", bd = 0, justify = RIGHT)
input_field.grid(row = 0, column = 0)
input_field.pack(ipady = 10) # 'ipady' is internal padding to increase the height of input field
# creating another 'Frame' for the button below the 'input_frame'
btns_frame = Frame(window, width = 312, height = 272.5, bg = "grey")
btns_frame.pack()
# first row
button_a = Button(btns_frame, text = "A", fg = "black", width = 10, height = 3, bd = 0, bg = "#eee", cursor = "hand2", command = lambda: btn_click("A"))
button_a.grid(row = 0, column = 1, padx = 1, pady = 1)
button_b = Button(btns_frame, text = "B", fg = "black", width = 10, height = 3, bd = 0, bg = "#eee", cursor = "hand2", command = lambda: btn_click("B")).grid(row = 0, column = 2, padx = 1, pady = 1)
button_del = Button(btns_frame, text = "Del", fg = "black", width = 10, height = 3, bd = 0, bg = "#eee", cursor = "hand2", command = lambda: btn_clear()).grid(row = 0, column = 3, padx = 1, pady = 1)
#while True:
# button_a.config(bg = 'yellow')
# time.sleep(1)
# button_a.config(bg = 'black')
window.mainloop()
Nun wuerde ich gerne den button_a "blinken" lassen. Jedoch sobald ich die while True Schleife aktiviere, wird mir gar keine GUI mehr angezeigt. Wie muss ich die Schleife in das Programm schreiben, so dass mir meine GUI noch angezeigt wird und mein button_a blinkt?
Vielleicht ist das eine dumme Frage, aber ich stehe im Moment wirklich auf dem Schlauch.
Viele Gruesse
SFR