tkinter-entry

How do you check if a widget has focus in Tkinter?

妖精的绣舞 提交于 2019-11-30 01:42:08
问题 from Tkinter import * app = Tk() text_field = Entry(app) text_field.pack() app.mainloop() I want to be able to check if text_field is currently selected or focused, so that I know whether or not to do something with its contents when the user presses enter. 回答1: If you want to do something when the user presses enter only if the focus is on the entry widget, simply add a binding to the entry widget. It will only fire if that widget has focus. For example: import tkinter as tk root = tk.Tk()

tkinter python entry height

℡╲_俬逩灬. 提交于 2019-11-29 07:16:50
I'm making a simple app just to practice python in which I want to write text as if it were Notepad. However, I can't make my entry bigger. I'm using tkinter for this. Does anybody know how to make the height of an entry bigger? I tried something like this: f = Frame() f.pack() e = Entry(f,textvariable=1,height=20) e.pack() I know this doesn't work because there isn't a property of "height". However, I see that there is a width property. It sounds like you are looking for tkinter.Text , which allows you to adjust both the height and width of the widget. Below is a simple script to demonstrate:

Get contents of a Tkinter Entry widget

自作多情 提交于 2019-11-26 22:56:44
I am creating an application and I want to use the entered values in the GUI Entry widget. How do I get the entered input from a Tkinter Entry widget? root = Tk() ... entry = Entry(root) entry.pack() root.mainloop() Bryan Oakley You need to do two things: keep a reference to the widget, and then use the get() method to get the string. Here's an example: self.entry = Entry(...) ... print("the text is", self.entry.get()) Someones_Name Here's an example: import tkinter as tk class SampleApp(tk.Tk): def __init__(self): tk.Tk.__init__(self) self.entry = tk.Entry(self) self.button = tk.Button(self,

Get contents of a Tkinter Entry widget

心已入冬 提交于 2019-11-26 06:46:26
问题 I am creating an application and I want to use the entered values in the GUI Entry widget. How do I get the entered input from a Tkinter Entry widget? root = Tk() ... entry = Entry(root) entry.pack() root.mainloop() 回答1: You need to do two things: keep a reference to the widget, and then use the get() method to get the string. Here's an example: self.entry = Entry(...) ... print("the text is", self.entry.get()) 回答2: Here's an example: import tkinter as tk class SampleApp(tk.Tk): def __init__

How to set the text/value/content of an `Entry` widget using a button in tkinter

让人想犯罪 __ 提交于 2019-11-26 05:36:14
问题 I am trying to set the text of an Entry widget using a button in a GUI using the tkinter module. This GUI is to help me classify thousands of words into five categories. Each of the categories has a button. I was hoping that using a button would significantly speed me up and I want to double check the words every time otherwise I would just use the button and have the GUI process the current word and bring the next word. The command buttons for some reason are not behaving like I want them to

Why is Tkinter Entry's get function returning nothing?

喜你入骨 提交于 2019-11-25 23:47:30
问题 I\'m trying to use an Entry field to get manual input, and then work with that data. All sources I\'ve found claim I should use the get() function, but I haven\'t found a simple working mini example yet, and I can\'t get it to work. I hope someone can tel me what I\'m doing wrong. Here\'s a mini file: from tkinter import * master = Tk() Label(master, text=\"Input: \").grid(row=0, sticky=W) entry = Entry(master) entry.grid(row=0, column=1) content = entry.get() print(content) # does not work