Python Forum
[Tkinter] Tkinter window issue - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] Tkinter window issue (/thread-14895.html)



Tkinter window issue - frequency - Dec-22-2018

Hello,
I am trying to make a popup window when a user enters a str value.Such as "$$@","sdasd","2y"
    def check(self):
        self.t1=self.entry1.get()
        self.t2=self.entry2.get()
        self.t3=self.entry3.get()
        self.t4=self.entry4.get()
        
        if ValueError:  #MESSING AROUND HERE!
            root.withdraw()
            alertwindow=Tk()
            alertwindow.geometry('300x80')
            alertwindow.title("Προσοχή!")
            alertlabel=Label(alertwindow,text="Δεν εβαλες ακεραιους αριθμους!")
            alertlabel.pack()
            alertbutton=Button(alertwindow,text="Ξαναπροσπάθησε",command=self.killer)#RESTARTS THE PROGRAM WHEN THE BUTTON IS PRESSED 
            alertbutton.pack(pady=10,padx=10)
        
        #THE CODE BELOW IS THE NEXT LOGICAL STEP
        if self.t1!=self.t3 or self.t2!=self.t4:
            self.answer=Label(self.root,text="Δεν μπορείς να προσθέσεις πίνακες διαφορετικών διαστάσεων",font="Arial 15")
            self.answer.grid(row=9,column=1)
            self.clear=Button(self.root,text="ξαναπροσπάθησε",font="Arial 12",command=self.refresh)
            self.clear.grid(row=11,column=1)
        else:
            self.creation()
           
It will run,BUT.Even though i enter a number like 2 or 4,i will still be promped to restart the programm.This is all a part of the code since i made it work before,but now i keep hitting my head on the wall for not making it work. Tkinter is imported as
from  tkinter import * 
Thanks


RE: Tkinter window issue - Larz60+ - Dec-23-2018

it's hard to figure out what:
if self.t1!=self.t3 or self.t2!=self.t4:
does without seeing the Entry widget definitions, or at at least a list of (verified) contents.


RE: Tkinter window issue - woooee - Dec-23-2018

For starters, alertwindow should be a Toplevel. When there is more than one instance of Tk(), the results are unpredictable.


RE: Tkinter window issue - frequency - Dec-23-2018

This is the default fuction
  def check(self):
        self.t1=self.entry1.get()
        self.t2=self.entry2.get()
        self.t3=self.entry3.get()
        self.t4=self.entry4.get()
        if self.t1!=self.t3 or self.t2!=self.t4:
            self.answer=Label(self.root,text="Δεν μπορείς να προσθέσεις πίνακες διαφορετικών διαστάσεων",font="Arial 15")
            self.answer.grid(row=9,column=1)
            self.clear=Button(self.root,text="Ξαναπροσπάθησε",font="Arial 12",command=self.refresh)
            self.clear.grid(row=11,column=1)      
        else:
            self.creation()
My theory is that,if we have a ValueError,the program would do something. In this case lets say,restart!
Using the above def,everything is ok. But,adding
if ValueError:
           self.killer()
After the get fuctions,if i type a legit number like 2,3,4,5,6 the code will restart!
    def killer(self): 
        os.execl(sys.executable, sys.executable, *sys.argv)
The fuction is called since we have a ValueError,but we do we have a ValueError?


RE: Tkinter window issue - frequency - Dec-24-2018

I made it work. Thanks to everybody! Toplevel will be my way to go with windows now.
  def check(self):
        alpha="abcdefghijklnopqrstuvwxyz"
        alpha_cap=alpha.upper()
        alpha=alpha+alpha_cap
        print (alpha_cap)
        self.t1=self.entry1.get()
        self.t2=self.entry2.get()
        self.t3=self.entry3.get()
        self.t4=self.entry4.get()
        
        if self.t1 in alpha or self.t2 in alpha or self.t3 in alpha or self.t4 in alpha:
            root.withdraw()
            alertwindow=Toplevel()
            alertlabel=Label(alertwindow,text="Παρακαλω,βαλε μονο ακαιρεους αριθμους!")
            alertlabel.pack()
            alertbutton=Button(alertwindow,text="Ξαναπροσπάθησε",command=self.restart)
            alertbutton.pack()
            
        if self.t1!=self.t3 or self.t2!=self.t4:
            self.answer=Label(self.root,text="Δεν μπορείς να προσθέσεις πίνακες διαφορετικών διαστάσεων",font="Arial 15")
            self.answer.grid(row=9,column=1)
            self.clear=Button(self.root,text="Ξαναπροσπάθησε",font="Arial 12",command=self.refresh)
            self.clear.grid(row=11,column=1)      
        else:
            self.creation()