Я пытаюсь изучить 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
Размещение текстового поля рядом с текстом в tkinter ⇐ Python
Программы на Python
-
Anonymous
1764097437
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)
Подробнее здесь: [url]https://stackoverflow.com/questions/79830073/placing-text-box-next-to-text-in-tkinter[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия