zergon321
@zergon321

Проблемы с GUI Tkinter — почему элемент управления (Label) находится не там, где надо?

Label с текстом "Choose a variant" должен находиться после текстового поля __text_bold, но находится перед ним. Почему?

from tkinter import *

class Shell(Frame):

	def __init__(self, window):
		super().__init__(window)
		self.grid()
		self.__clicked = 0
		self.__init_widgets()

	def __init_widgets(self):
		self.__lbl = Label(self, text = "Button clicked: " + str(self.__clicked))
		self.__lbl.grid(row = 0, column = 0, columnspan = 2, sticky = W)

		Button(self, text = "Click on me", command = self.__clicker).grid(row = 0, column = 2, columnspan = 2, sticky = E)

		self.__ent = Entry(self)
		self.__ent.grid(row = 3, column = 0, columnspan = 2, sticky = W)

		Button(self, text = "Enter", command = self.__input_bold).grid(row = 3, column = 2, sticky = W)

		self.__fuck_label = Label(self, text = "Hey, bitch")
		self.__fuck_label.grid(row = 5, column = 2, columnspan = 3)

		self.__text_bold = Text(width = 40, height = 5, wrap = WORD)
		self.__text_bold.grid(row = 6, column = 0, sticky = W, columnspan = 5)

		Label(self, text = "Choose a variant:").grid(row = 18, column = 0, sticky = W, columnspan = 2)

		self.__fuck_me = BooleanVar()
		self.__fuck_my_mom = BooleanVar()

		Checkbutton(text = "Fuck me pls", variable = self.__fuck_me, command = self.__checkbutton_handler).grid(row = 22, column = 0, columnspan = 2, sticky = W)
		Checkbutton(text = "Fuck my mom pls", variable = self.__fuck_my_mom, command = self.__checkbutton_handler).grid(row = 24, column = 0, columnspan = 2, sticky = W)

		self.__fuck_text = Text(width = 30, height = 10, wrap = WORD)
		self.__fuck_text.grid(row = 40, column = 0, columnspan = 3, sticky = W)

	def __clicker(self):
		self.__clicked += 1
		self.__lbl["text"] = "Button clicked: " + str(self.__clicked)

	def __input_bold(self):
		if self.__ent.get() == "Fuck you":
			self.__fuck_label["text"] = "O_0"

			self.__text_bold.delete(0.0, END)
			self.__text_bold.insert(0.0, 
"""watafak mazafaka
you're fucking loser
asshole""")
		else:
			self.__fuck_label["text"] = "What a fuck did you say?!"
			self.__text_bold.delete(0.0, END)
			self.__text_bold.insert(0.0, 
"""your mom is a fucking whore
you're fool""")

	def __checkbutton_handler(self):
		if self.__fuck_me.get() and not self.__fuck_my_mom.get():
			self.__fuck_text.delete(0.0, END)
			self.__fuck_text.insert(0.0, "My dick is biiig, my dick is very biiiiig!!!")
		elif self.__fuck_my_mom.get() and not self.__fuck_me.get():
			self.__fuck_text.delete(0.0, END)
			self.__fuck_text.insert(0.0, "Your mommy will be satisfacted")
		elif self.__fuck_me.get() and self.__fuck_my_mom.get():
			self.__fuck_text.delete(0.0, END)
			self.__fuck_text.insert(0.0, "OK LET'S GOOOO")
		elif not self.__fuck_me.get() and not self.__fuck_my_mom.get():
			self.__fuck_text.delete(0.0, END)
			self.__fuck_text.insert(0.0, "Your resistance only makes my penis HARDER!!!")



if __name__ == "__main__":
	main_window = Tk()

	main_window.title("Clicker")
	main_window.geometry("600x600")

	shell = Shell(main_window)

	main_window.mainloop()
  • Вопрос задан
  • 140 просмотров
Пригласить эксперта
Ответы на вопрос 1
@tikhenko
Потому что в ряде компонентов пропущен self. А должно быть:
self.__text_bold = Text(self, width = 40, height = 5, wrap = WORD)
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы