Размещение текстового поля рядом с текстом в tkinterPython

Программы на Python
Ответить
Anonymous
 Размещение текстового поля рядом с текстом в tkinter

Сообщение Anonymous »

Я пытаюсь изучить tkinter, как мне отредактировать этот код, чтобы текстовое поле находилось непосредственно рядом с оператором ввода? Я попытался поместить текстовое поле в первый столбец с выравниванием по середине и правому краю, но оно все равно слишком далеко.
def processTitle(window):

# allowing the user to enter their title
Label(window, text='Enter your title: ').grid(row=1, column=0, sticky = "W", ipadx =0 , padx=10, pady=0) # text box
usersTitle = Entry(window) # entry field
usersTitle.grid(row=1, column=0, columnspan= 2, sticky = "", ipadx =0, padx=0, pady=20) # placing the entry field next to the first question

# label for displaying the error message if the user's title isn't valid
titleValidationMessage = Label(window, text="")

def titleValidation(event):
title = usersTitle.get() #retieving the data from the text box next to title
correctTitles = ["mr", "mrs", "miss", "ms", "dr", "sir", "lord"]
if title.lower() in correctTitles:
titleValidationMessage.grid_forget() # hide the label when there's no error message
titleValidationMessage.config(text="") # clearing error messages from any previous input for first name
else:
titleValidationMessage.grid(row=1, column=2, sticky = "w", ipadx = 3,padx=10) # position of the error message
titleValidationMessage.config(text="Please enter a legal title (Mr,Mrs,Miss,Ms,Dr,Sir,Lord)")

# Bind the focus-out event - when the user clicks out of the text box the data will be validated
usersTitle.bind("", titleValidation)

#returing the title to the main program
return usersTitle

Мой макет сетки настроен ниже

# Ensure all rows have a minimal weight to prevent vertical jumping
for i in range(20): # Configuring 10 rows
createSAccountWindow.grid_rowconfigure(i, weight=0)

# Column 0: Size for the entry labels
createSAccountWindow.grid_columnconfigure(0, weight=0, minsize=100)

# Column 1: Size for the Entry boxes
# The sticky="nsew" on the Entry widget will ensure it fills this fixed column width.
createSAccountWindow.grid_columnconfigure(1, weight=0, minsize=200)

# Column 2: This column will absorb all extra horizontal space (weight=1).
# This keeps the other columns stable and pins the error message to the left edge of this flexible space.
createSAccountWindow.grid_columnconfigure(2, weight=1)


Подробнее здесь: https://stackoverflow.com/questions/798 ... in-tkinter
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»