TSM AdjustCapsLockLEDForKeyTransitionHandling - _ISSetPhysicalKeyboardCapsLockLED Inhibit - python

Python: 3.9.5
Os: macOS 11.4
from tkinter import *
window = Tk()
e1_value = StringVar()
def printText():
print(e1_value.get())
# def printText():
# print('HelloWorld!')
b1 = Button(window, text = "Excute", command = printText())
b1.grid(row = 0, column = 0)
e1 = Entry(window, textvariable = e1_value)
e1.grid(row = 0, column = 1)
t1 = Text(window, height = 1, width = 20)
t1.grid(row = 0, column = 2)
window.mainloop()
I met an error that was printed out in the terminal so I couldn't print out the value into the terminal. The error said,
"TSM AdjustCapsLockLEDForKeyTransitionHandling -
_ISSetPhysicalKeyboardCapsLockLED Inhib"
, when I type something into Entry window. I've been searching for the answer on Google, but I still can't find it. Do you happen to know how to solve the problem?
Besides, I could see 'Hellow world!' only once even if I pushed the Button a few times.
I'm not acquainted with tkinter so I don't know what to do.

I deleted the parenthesis after printText.
b1 = Button(window, text = "Excute", command = printText)
I could print out what I typed in the Entry box. I still saw "TSM AdjustCapsLockLEDForKeyTransitionHandling - _ISSetPhysicalKeyboardCapsLockLED Inhib" though.
from tkinter import *
window = Tk()
e1_value = StringVar()
def printText():
print(e1_value.get())
# def printText():
# print('HelloWorld!')
b1 = Button(window, text = "Excute", command = printText)
b1.grid(row = 0, column = 0)
e1 = Entry(window, textvariable = e1_value)
e1.grid(row = 0, column = 1)
t1 = Text(window, height = 1, width = 20)
t1.grid(row = 0, column = 2)
window.mainloop()

It's because you have another language in your keyboard preferences.
Delete the language that is not english in your keyboard preferences

Related

how to create tkinter entry box with multiline

How to create large extry box in python tkinter?
I have tried to use height in ttk.entry() but the error show :
_tkinter.TclError: unknown option "-height"
from tkinter import *
from tkinter import ttk
GUI = Tk()
GUI.title("myTest")
GUI.geometry("700x700")
S_NOTE = StringVar()
E_NOTE = ttk.Entry(GUI, textvariable = S_NOTE, font = FONT1, width = 40, height = 20)
E_NOTE.grid(row = 0, column = 0, columnspan = 2, rowspan = 2)
GUI.mainloop()
I also need to get the StringVar from the entrybox and fix the position (such as using grid)
Looks like you are using a bad way to do this..
see.. You can use the Text widget to do the same..
Example:
from tkinter import *
GUI = Tk()
GUI.title("myTest")
GUI.geometry("700x700")
def set_text_to_variable():
global E_NOTE
global S_NOTE
S_NOTE = E_NOTE.get(1.0,END)
print("S_NOTE = ",S_NOTE)
E_NOTE = Text(GUI, font = "Segoe", width = 40, height = 20)
E_NOTE.grid(row = 0, column = 0, columnspan = 2, rowspan = 2)
Change_variable = Button(GUI, text = "CHANGE THE \"S_NOTE\" VARIABLE", command = set_text_to_variable)
Change_variable.grid()
GUI.mainloop()

Python GUI that contains a Countdown Timer and a String that were handed over during the runtime

I am currently trying to implement a GUI as kind of a 'Presentors' Toolkit'.
It shall contain how much time you have left on your presentation and who shall be the next speaker.
I manage to build the GUI with boxes, where I can insert the time and the name of the next speaker, but somewhat I can't manage to get my head around the display of name and time (updated every second).
The program will start, when I hit the start button, but also will not terminate.
I have tried a couple of things and also checked out other stack overflow entries but couldn't manage to transfer those approaches to mine.
My code looks like this:
from tkinter import *
import time
import datetime
#build the GUI
window = Tk()
window.title("presenters Toolkit")
lbl_duration = Label(window, text = "duration [mins]")
lbl_duration.grid(column = 0, row = 0)
presentationDuration = Entry(window, width = 10)
presentationDuration.grid(column = 1, row = 0)
lbl_speaker = Label(window, text = "next Speaker")
lbl_speaker.grid(column = 2, row = 0)
nextSpeaker = Entry(window, width = 25)
nextSpeaker.grid(column = 3, row = 0)
lbl = Label(window, text = "", font = ("Arial Bold", 50))
lbl.grid(column = 1, row = 1)
left_Time = Label(window, text ="--", font = ("Arial Bold", 50))
left_Time.grid(column = 0, row = 4)
mid_Time = Label(window, text = ":", font = ("Arial Bold", 50))
mid_Time.grid(column = 1, row = 4)
right_Time = Label(window, text = "--", font = ("Arial Bold", 50))
right_Time.grid(column = 2, row = 4)
btn = Button(window, text = "start", command = clicked)
btn.grid(column = 1, row = 3)
#method, that will act upon clicking the 'start button'
def clicked():
t = float(presentationDuration.get())
nSpeaker = nextSpeaker.get()
t = int(t*60)
update(t, nSpeaker)
#method, that shall update the labels according to the time and that shall do this only once every second
def update(t, nSpeaker):
h = int(t//3600)
m = int(t//60)
s = int(t-3600*h-60*m)
while t >= 0:
left_Time.configure(text = m)
mid_Time.configure(text = ":")
right_Time.configure(text = s)
lbl.configure(text = nSpeaker, bg = "red", font = ("Arial Bold", 50))
t = t - 1
window.after(1000, update(t, nSpeaker))
window.mainloop()
I still have the calculations for the hour included, though I believe that won't be necessary since presentations usually don't go that long.
Thank you very much for any approach to help me!
All the best :)

Storing entry input from GUI

Lets say I have this code
import math
from tkinter import *
def close_window():
root.destroy()
def fileName():
filename = content.get()
return filename;
root = Tk()
content = StringVar()
L2 = Label(root, text = "The Program").grid(row = 0, sticky = E)
L1 = Label(root, text = "Enter filename").grid(row = 1, column = 0, sticky = E)
E1 = Entry(root, bd = 5, textvariable = content).grid(row = 1, column = 1)
B1 = Button(root, text = "Ok", command = fileName).grid(row = 2, column = 0 )
B2 = Button(root, text = "Quit", command = close_window).grid(row = 2, column = 1)
root.mainloop()
print(fileName())
Now the problem is I want to store the content I enter in E1 (so I later can do things to it) but how do I access it "outside" of the GUI?
The program I want to make is that the user enters a file name, then it runs a bunch of functions on the input and then produce a textmessage based on whats given, but I cant access the input since
fileName()
doesnt return anything.
Not sure if this does what you wanted but now it prints on button click and you have you filename variable set to content.get()
import math
from tkinter import *
def close_window():
root.destroy()
def fileName():
filename = content.get()
return filename;
def combine_funcs(*funcs):
def combined_func(*args, **kwargs):
for f in funcs:
f(*args, **kwargs)
return combined_func
def prnt():
print(content.get())
root = Tk()
content = StringVar()
L2 = Label(root, text = "The Program").grid(row = 0, sticky = E)
L1 = Label(root, text = "Enter filename").grid(row = 1, column = 0, sticky = E)
E1 = Entry(root, bd = 5, textvariable = content).grid(row = 1, column = 1)
B1 = Button(root, text = "Ok", command = combine_funcs(fileName,prnt)).grid(row = 2, column = 0 )
B2 = Button(root, text = "Quit", command = close_window).grid(row = 2, column = 1)
root.mainloop()
print(fileName())

Radio Buttons tkinter python

I have an issue where all my radio buttons are selected when I try to click one of them. It is for a conversion calculator, so once I solve this issue I will be able to carry the same code over for my other conversions. Any help is greatly appreciated.
Thanks,
Jamie
`from tkinter import*
from tkinter import ttk
class GUI:
def __init__(self, root):
notebook = ttk.Notebook(root)
notebook.pack()
self.temp_frame = ttk.Frame(notebook)
self.length_frame = ttk.Frame(notebook)
self.weight_frame = ttk.Frame(notebook)
#-----------------Length------------------------#
notebook.add(self.length_frame, text = "Length")
#Radio Buttons
v = StringVar()
MODES = ["mm","cm","Inch","Feet","Yards","Metre","Km","Miles"]
v.set("0") # initialize
r=0
for r in range(len(MODES)):
b = ttk.Radiobutton(self.length_frame, text=MODES[r], variable=v )
b.grid(row=r ,column = 0, sticky = W)
#Radio Buttons
v1 = StringVar()
MODES1 = ["mm","cm","Inch","Feet","Yards","Metre","Km","Miles"]
v1.set("0")#initialize
r=0
for r in range(len(MODES1)):
b = ttk.Radiobutton(self.length_frame, text=MODES1[r], variable=v1 )
b.grid(row=r ,column = 6, sticky = W)
#Entry Box
self.Text_length_left = StringVar()
self.entry_length_left = ttk.Entry(self.length_frame, textvariable = self.Text_length_left, width = 15)
self.entry_length_left.grid(row = 4, column = 2)
self.Text_length_right = StringVar()
self.entry_length_right = ttk.Entry(self.length_frame, textvariable = self.Text_length_right, width = 15, state = "readonly")
self.entry_length_right.grid(row = 4, column = 4)
#Label
self.label_3 = Label(self.length_frame, text = "From:")
self.label_3.grid(row = 3, column = 2)
self.label_4 = Label(self.length_frame, text = "To:")
self.label_4.grid(row = 3, column = 4)
self.label_1 = Label(self.length_frame, text = "-->")
self.label_1.grid(row = 4, column = 3)
self.label_2 = Label(self.length_frame, text = " ")
self.label_2.grid(row = 4, column = 5)
#---------------------Temp Frame ----------------------#
notebook.add(self.temp_frame, text = "Temperature")
if __name__ == "__main__":
root = Tk()
app = GUI(root)
root.mainloop()`
You never set the value keyword. This is what's stored in the control variable for a group of radiobuttons when clicked.

Python Tkinter not opening when using .grid()

I am working through online tutorials to learn how to make a GUI with Tkinter. But i am having an issue when using the .grid() function.
Here is what i have so far:
from Tkinter import *
root = Tk()
title = Label(root, text = "Hello World")
title.pack()
name = Label(root, text = "Name")
password = Label(root, text = "Password")
entry_name = Entry(root)
entry_password = Entry(root)
name.grid (row = 0, sticky = E)
password.grid (row = 0, sticky = E)
entry_name.grid (row = 0, column = 1)
entry_password.grid (row = 1, column = 1)
check = Checkbutton(root, text = "Keep me logged in")
check.grid(columnspan = 2)
root.mainloop()
So the problem im having is as soon as i include that first line:
name.grid(row = 0, sticky = E)
And then run the script, there are no errors, but nothing opens. The program just hangs and i have to close the command prompt in order to regain control.
If i comment out all the lines using .grid() they program works fine and will open a window with my title inside it.
So, does anyone know what im doing wrong?
Im using Python 2.7
You cannot use both pack and grid with two or more widgets that share the same parent. In your case you're using pack for title and grid for everything else. Use one or the other.
Keep grid geometry manager consistent so use title.grid().
from tkinter import *
root = Tk()
title = Label(root, text = "Hello World")
title.grid()
name = Label(root, text = "Name")
password = Label(root, text = "Password")
entry_name = Entry(root)
entry_password = Entry(root)
name.grid(row = 0, sticky = E)
password.grid (row = 0, sticky = E)
entry_name.grid (row = 0, column = 1)
entry_password.grid (row = 1, column = 1)
check = Checkbutton(root, text = "Keep me logged in")
check.grid(columnspan = 2)
root.mainloop()

Categories

Resources