Я новичок в программировании. Я использую Tkinter в Python. Я пытаюсь сделать так, чтобы метки в моей программе располагались рядом друг с другом (с небольшим пространством между ними, примерно 50 пикселей). Два ярлыка, которые я хотел бы иметь рядом: «ингредиенты» и «шаги». Я пытался создать рамку так, чтобы они могли располагаться рядом друг с другом, но ингредиенты всегда располагались над ступенями, а не рядом. Я просмотрел другие вопросы на StackOverflow, но не смог спокойно применить их к своей программе. Могу ли я сделать так, чтобы две мои метки, этапы и ингредиенты, располагались рядом с некоторым пространством между ними. Буду ли я продолжать использовать фрейм или использовать .grid или что-то еще?
Любая помощь будет очень признательна!! И если бы вы могли добавлять комментарии в свой код, чтобы я знал, что вы делаете, это было бы здорово! Спасибо!
import Tkinter
class Cookbook(Tkinter.Tk):
def __init__(self):
Tkinter.Tk.__init__(self)
self.title("Cookbook")
self.geometry("500x500+0+0")
self.button = []
for r in range(1):
for c in range(1):
b = Button(self).grid(row=r,column=c)
self.button.append(b)
class Button(Tkinter.Button):
def __init__(self,parent):
b = Tkinter.Button.__init__(self, parent, text="Add A New Recipie", height=8, width=15, command=self.make_window)
def make_window(self):
popwindow = IngredientAdder()
popwindow.title_box()
popwindow.ingredients_box()
popwindow.steps_box()
popwindow.init_gui()
class IngredientAdder(Tkinter.Tk):
def __init__(self):
Tkinter.Tk.__init__(self)
self.title("Recipie")
self.geometry("550x500")
def title_box(self):
#Frame for the Title Label and the Title Entry Box
test = Tkinter.Frame(self, height=100, relief=Tkinter.SUNKEN)
test.pack(anchor=Tkinter.NW,side=Tkinter.TOP)
#putting in a Title LABEL and ENTRY BOX
Tkinter.Label(test,text="Title:").pack(anchor=Tkinter.NW,side=Tkinter.LEFT)
self.entry1 = Tkinter.Entry(test,width=450)
self.entry1.pack(anchor=Tkinter.NW,side=Tkinter.TOP)
def ingredients_box(self):
#Frame for the Ingredients Label and the Ingredients Entry Boxes
self.test2 = Tkinter.Frame(self, height=100,width=20, relief=Tkinter.SUNKEN)
self.test2.pack(anchor=Tkinter.NW,side=Tkinter.TOP)
#Put an Ingredients label at the top of the window and anchor it there
Tkinter.Label(self.test2,text="Ingredients:").pack(anchor=Tkinter.NW,side=Tkinter.TOP)
def steps_box(self):
#Frame for the Steps Label and the Steps Textbox
test3 = Tkinter.Frame(self, height=100,width=50, relief=Tkinter.SUNKEN)
test3.pack(anchor=Tkinter.NE,side=Tkinter.RIGHT)
#putting in an entry box and Steps label for the steps of the recepie
Tkinter.Label(test3,text="Steps:").pack(anchor=Tkinter.N,side=Tkinter.TOP)
self.entry2 = Tkinter.Text(test3,width=40,height=33,font="helvetica 12",padx=5,pady=5).pack(anchor=Tkinter.NE,side=Tkinter.TOP)
def title_save(self):
self.title_entries.append(self.entry1)
def text_box(self):
self.text_entries.append(self.entry2)
# function to add new ingredients
def add_ingredient_entry(self):
entry = Tkinter.Entry(self.test2)
entry.pack(anchor=Tkinter.NW,side=Tkinter.TOP)
self.ingredient_entries.append(entry)
# get contents of all entry boxes
def save_recipe(self):
for words in self.title_entries:
print words.get()
for ingredient in self.ingredient_entries:
print ingredient.get()
for text in self.text_entries:
print text.get('1.0','end')
print "[Recipie saved]"
# build initial widgets
def init_gui(self):
# title saved in this array
self.title_entries = []
# this is a list of ingredients entry boxes
self.ingredient_entries = []
#this saves the list in this array, hopefully
self.text_entries = []
#Making a frame at the bottom to put both buttons in line
self.test4 = Tkinter.Frame(self,height=10, relief=Tkinter.SUNKEN)
self.test4.pack(side=Tkinter.BOTTOM)
#Put these two buttons at the bottom of the window and anchor them there
Tkinter.Button(self.test4,text="Save recipe",command=self.save_recipe, width=15).pack(anchor=Tkinter.SE,side=Tkinter.RIGHT)
Tkinter.Button(self.test4,text="Add ingredient",command=self.add_ingredient_entry, width=15).pack(anchor=Tkinter.NW,side=Tkinter.LEFT)
#New ingredients will be added between the label and the buttons
self.add_ingredient_entry()
top = Cookbook()
top.mainloop()
Подробнее здесь: https://stackoverflow.com/questions/240 ... e-with-one
Tkinter Python: как я могу использовать виджет Frame, чтобы совместить метки друг с другом? ⇐ Python
Программы на Python
1770375935
Anonymous
Я новичок в программировании. Я использую Tkinter в Python. Я пытаюсь сделать так, чтобы метки в моей программе располагались рядом друг с другом (с небольшим пространством между ними, примерно 50 пикселей). Два ярлыка, которые я хотел бы иметь рядом: «ингредиенты» и «шаги». Я пытался создать рамку так, чтобы они могли располагаться рядом друг с другом, но ингредиенты всегда располагались над ступенями, а не рядом. Я просмотрел другие вопросы на StackOverflow, но не смог спокойно применить их к своей программе. Могу ли я сделать так, чтобы две мои метки, этапы и ингредиенты, располагались рядом с некоторым пространством между ними. Буду ли я продолжать использовать фрейм или использовать .grid или что-то еще?
Любая помощь будет очень признательна!! И если бы вы могли добавлять комментарии в свой код, чтобы я знал, что вы делаете, это было бы здорово! Спасибо!
import Tkinter
class Cookbook(Tkinter.Tk):
def __init__(self):
Tkinter.Tk.__init__(self)
self.title("Cookbook")
self.geometry("500x500+0+0")
self.button = []
for r in range(1):
for c in range(1):
b = Button(self).grid(row=r,column=c)
self.button.append(b)
class Button(Tkinter.Button):
def __init__(self,parent):
b = Tkinter.Button.__init__(self, parent, text="Add A New Recipie", height=8, width=15, command=self.make_window)
def make_window(self):
popwindow = IngredientAdder()
popwindow.title_box()
popwindow.ingredients_box()
popwindow.steps_box()
popwindow.init_gui()
class IngredientAdder(Tkinter.Tk):
def __init__(self):
Tkinter.Tk.__init__(self)
self.title("Recipie")
self.geometry("550x500")
def title_box(self):
#Frame for the Title Label and the Title Entry Box
test = Tkinter.Frame(self, height=100, relief=Tkinter.SUNKEN)
test.pack(anchor=Tkinter.NW,side=Tkinter.TOP)
#putting in a Title LABEL and ENTRY BOX
Tkinter.Label(test,text="Title:").pack(anchor=Tkinter.NW,side=Tkinter.LEFT)
self.entry1 = Tkinter.Entry(test,width=450)
self.entry1.pack(anchor=Tkinter.NW,side=Tkinter.TOP)
def ingredients_box(self):
#Frame for the Ingredients Label and the Ingredients Entry Boxes
self.test2 = Tkinter.Frame(self, height=100,width=20, relief=Tkinter.SUNKEN)
self.test2.pack(anchor=Tkinter.NW,side=Tkinter.TOP)
#Put an Ingredients label at the top of the window and anchor it there
Tkinter.Label(self.test2,text="Ingredients:").pack(anchor=Tkinter.NW,side=Tkinter.TOP)
def steps_box(self):
#Frame for the Steps Label and the Steps Textbox
test3 = Tkinter.Frame(self, height=100,width=50, relief=Tkinter.SUNKEN)
test3.pack(anchor=Tkinter.NE,side=Tkinter.RIGHT)
#putting in an entry box and Steps label for the steps of the recepie
Tkinter.Label(test3,text="Steps:").pack(anchor=Tkinter.N,side=Tkinter.TOP)
self.entry2 = Tkinter.Text(test3,width=40,height=33,font="helvetica 12",padx=5,pady=5).pack(anchor=Tkinter.NE,side=Tkinter.TOP)
def title_save(self):
self.title_entries.append(self.entry1)
def text_box(self):
self.text_entries.append(self.entry2)
# function to add new ingredients
def add_ingredient_entry(self):
entry = Tkinter.Entry(self.test2)
entry.pack(anchor=Tkinter.NW,side=Tkinter.TOP)
self.ingredient_entries.append(entry)
# get contents of all entry boxes
def save_recipe(self):
for words in self.title_entries:
print words.get()
for ingredient in self.ingredient_entries:
print ingredient.get()
for text in self.text_entries:
print text.get('1.0','end')
print "[Recipie saved]"
# build initial widgets
def init_gui(self):
# title saved in this array
self.title_entries = []
# this is a list of ingredients entry boxes
self.ingredient_entries = []
#this saves the list in this array, hopefully
self.text_entries = []
#Making a frame at the bottom to put both buttons in line
self.test4 = Tkinter.Frame(self,height=10, relief=Tkinter.SUNKEN)
self.test4.pack(side=Tkinter.BOTTOM)
#Put these two buttons at the bottom of the window and anchor them there
Tkinter.Button(self.test4,text="Save recipe",command=self.save_recipe, width=15).pack(anchor=Tkinter.SE,side=Tkinter.RIGHT)
Tkinter.Button(self.test4,text="Add ingredient",command=self.add_ingredient_entry, width=15).pack(anchor=Tkinter.NW,side=Tkinter.LEFT)
#New ingredients will be added between the label and the buttons
self.add_ingredient_entry()
top = Cookbook()
top.mainloop()
Подробнее здесь: [url]https://stackoverflow.com/questions/24016614/tkinter-python-how-can-i-use-the-frame-widget-to-put-my-labels-in-line-with-one[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия