не скрываются кнопки
не скрываются кнопки conf()
хотелось бы чтоб после нажатия исчезали настройки даты dateSeting()
import tkinter
from tkinter import *
import tkinter as tk
from tkinter import messagebox
import datetime
from datetime import datetime
import webbrowser
import keyboard
import os
import sys
# func
def hellp():
webbrowser.open('https://web.telegram.org/#/im?p=@got4ikGRIFZ', new=2)
def pluseY():
global dateYear1
dateYear1 = dateYear1 + 1
year.config(text=dateYear1)
def minY():
global dateYear1
dateYear1 = dateYear1 - 1
year.config(text = dateYear1)
# 2 -------
def pluseM():
global dateMonth1
dateMonth1 = dateMonth1 + 1
month.config(text = dateMonth1)
if dateMonth1 == 12:
dateMonth1 = 0
def minM():
global dateMonth1
dateMonth1 = dateMonth1 - 1
month.config(text = dateMonth1)
if dateMonth1 == 0:
dateMonth1 = 12
# 3 -------
def pluseD():
global dateDay1
dateDay1 = dateDay1 + 1
day.config(text = dateDay1)
if dateDay1 == 31:
dateDay1 = 0
def minD():
global dateDay1
dateDay1 = dateDay1 - 1
day.config(text = dateDay1)
if dateDay1 == 0:
dateDay1 = 31
# ================================================================
def conf():
global year, pluY, miY, month, pluM, miM, day, pluD, miD
global dateYear1, dateYear1, dateDay1, dateA, date
year.pack_forget()
day.pack_forget()
month.pack_forget()
pluY.pack_forget()
pluD.pack_forget()
pluM.pack_forget()
miY.pack_forget()
miD.pack_forget()
miM.pack_forget()
dateA = str(dateYear1) + ":" + str(dateMonth1) + ":" + str(dateDay1)
date.config(text=dateA)
def none():
pass
# =-=-=-==-===-==-===-==-=
def dateSeting():
global dateA, date
global year, pluY, miY, month, pluM, miM, day, pluD, miD
global dateYear1, year, day
global dateMonth1, month, dateDay1
current_datetime = datetime.now()
dateMonth1 = (current_datetime.month)
dateYear1 = (current_datetime.year)
dateDay1 = (current_datetime.day)
year = Label(text = dateYear1)
year.place(relx=0.485, rely=0.1)
pluY = Button(text=(">"), width = 4, bd = 0, bg='#bdc3c7', command = pluseY)
pluY.place(relx=0.535, rely=0.1)
miY = Button(text=("<"), width = 4, bd = 0, bg='#bdc3c7', command = minY)
miY.place(relx=0.435, rely=0.1)
# ---------------------------------
month = Label(text = dateMonth1)
month.place(relx=0.485, rely=0.12)
pluM = Button(text=(">"), width = 4, bd = 0, bg='#bdc3c7', command = pluseM)
pluM.place(relx=0.535, rely=0.12)
miM = Button(text=("<"), width = 4, bd = 0, bg='#bdc3c7', command = minM)
miM.place(relx=0.435, rely=0.12)
# ---------------------------------
day = Label(text = dateDay1)
day.place(relx=0.485, rely=0.14)
pluD = Button(text=(">"), width = 4, bd = 0, bg='#bdc3c7', command = pluseD)
pluD.place(relx=0.535, rely=0.14)
miD = Button(text=("<"), width = 4, bd = 0, bg='#bdc3c7', command = minD)
miD.place(relx=0.435, rely=0.14)
# ----------------
confirm = Button(text="Пременить", width = 15, bd = 0, bg='#bdc3c7', command = conf)
confirm.place(relx=0.435, rely=0.165)
def expensesF():
global dateYear1
global dateA, date
current_datetime = datetime.now()
dateYear = str(current_datetime.year)
dateMonth = str(current_datetime.month)
dateDay = str(current_datetime.day)
addButton = Button(text="Добавить", width=10, bg='#bdc3c7',bd=0, height=1).place(relx=0, rely=0.05)
item = Entry(width=20, bd=0).place(relx=0.12, rely=0.05)
dateA = dateYear+":"+dateMonth+":"+dateDay
date = Button(text=dateA, width=10, bg='#bdc3c7', bd=0, height=1, command=dateSeting)
date.place(relx=0.435, rely=0.053)
num = Spinbox(width=15, from_=100, to=999999999999, bd=0).place(relx=0.29, rely=0.053)
textNum = Label(text="Сумма:")
textItem = Label(text="Причина:")
textNum.place(relx=0.29, rely=0.03)
textItem.place(relx=0.12, rely=0.03)
expenses.config(bg='#2980b9')
def stat():
messagebox.showinfo('Статистика', 'Долги -')
def save(): #сохранить
messagebox.showinfo('Сохронино', 'Сохранение завершино')
def quit():#выход
sys.exit()
# -----------------------------
root = Tk()
root.geometry("750x900")
mainmenu = Menu(root)
root.title("Таблица расходов")
root.configure(background= "#ecf0f1")
# menu
root.config(menu=mainmenu)
filemenu = Menu(mainmenu, tearoff=0)
filemenu.add_command(label="Сохранить", command=save)
filemenu.add_command(label="Выход", command=quit)
helpmenu = Menu(mainmenu, tearoff=0)
helpmenu.add_command(label="Помощь", command= hellp)
helpmenu.add_command(label="Статистика", command= stat)
mainmenu.add_cascade(label="File", menu=filemenu)
mainmenu.add_cascade(label="About", menu=helpmenu)
# ------------------------------------------------
# tegs
expenses = Button(text="Расходы", width=10, height=1, bg='#3498db', highlightthickness=0, foreground = "white", font=("Bahnschrift"), bd=0, command=expensesF)
expenses.grid(row=0, column=0)
earnings = Button(text="Доход", width=10, height=1, bg='#3498db', highlightthickness=0, foreground = "white", font=("Bahnschrift"), bd=0)
earnings.grid(row=0, column=2)
debts = Button(text="Долги", width=10, height=1, bg='#3498db', highlightthickness=0, foreground = "white", font=("Bahnschrift"), bd=0)
debts.grid(row=0, column=4)
# ---------------------------
root.mainloop()
Ответы (1 шт):
Автор решения: Неправильный Енот
→ Ссылка
чтобы убрать какой-то объект из окна TKinter нужно написать название и добавить метод destroy() к объекту который вы хотите убрать. Например вот так:
def conf():
global year, pluY, miY, month, pluM, miM, day, pluD, miD
global dateYear1, dateYear1, dateDay1, dateA, date
year.pack_forget()
day.pack_forget()
month.pack_forget()
pluY.pack_forget()
pluD.pack_forget()
pluM.pack_forget()
miY.pack_forget()
miD.pack_forget()
miM.pack_forget()
dateA = str(dateYear1) + ":" + str(dateMonth1) + ":" + str(dateDay1)
date.config(text=dateA)
date.destroy()
year.destroy()
month.destroy()
day.destroy()
miY.destroy()
miD.destroy()
miM.destroy()
pluM.destroy()
pluD.destroy()
pluY.destroy()
Возможно есть вариант лучше, но я пользуюсь этим.