0

but he is returning directly the chackou and I want that only if it is chosen returns him

I'll simplify it so I can understand it, I need it in model.py, when the person chooses the "SIM" option that adds and updates the chekout with datatimenow, but I can not do it

Model.py

SAIDA_CHOICES = (
    ('Não', 'Não Pago'),
    ('Sim', 'Pago')
)

class MovRotativo(models.Model):
    checkin = models.DateTimeField(auto_now=True, blank=False, null=False,)
    checkout = models.DateTimeField(auto_now=True, null=True, blank=True)
    email = models.EmailField(blank=False)
    placa = models.CharField(max_length=7, blank=False)
    modelo = models.CharField(max_length=15, blank=False)
    valor_hora = models.DecimalField(
        max_digits=5, decimal_places=2, null=False, blank=False)
    pago = models.CharField(max_length=15, choices=PAGO_CHOICES)
    chk = models.CharField(max_length=15, choices=SAIDA_CHOICES)

     def saida(self):
        if self.chk == 'sim':
            return self.chk
        else:
            self.checkout = models.DateTimeField(auto_now=True)
            return self.checkout

1 Answer 1

1

The simplest way is to implement the entire window as a subclass of a tk Frame, and then destroy and recreate it. Your code might look something like this:

import Tkinter as tk

class Example(tk.Frame):
    def __init__(self, parent):
        tk.Frame.__init__(self, parent)
        <other code here...>

class Application:
    def __init__(self):
        self.root = tk.Tk()
        self.frame = None
        refreshButton = tk.Button(self.root, text="refresh", command=self.refresh)
        self.refresh()

    def refresh(self):
        if self.frame is not None:
            self.frame.destroy()
        self.frame = Example(self.root)
        self.frame.grid(...)

Though,there's nothing really magical about subclassing Frame. You just need to have a function that creates a frame and puts a bunch of widgets in it. When you want to refresh, just delete the frame and call your function again. Using a class is a bit more convenient, but a class isn't strictly necessary.

Sign up to request clarification or add additional context in comments.

3 Comments

very good, I'm going to use this, but my doubt is how to update the database with this button data
I'll simplify it so I can understand it, I need it in the model, when the person chooses the option "YES" it triggers and updates the chekout with the datatimenow
If you find my answer helpful please vote me up. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.