Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [Tkinter] Tkinter window issue
#1
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
Quote
#2
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.
Quote
#3
For starters, alertwindow should be a Toplevel. When there is more than one instance of Tk(), the results are unpredictable.
Quote
#4
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?
Quote
#5
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()
           
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Using Tkinter widgets on child window chewy1418 5 169 Jan-31-2020, 07:13 PM
Last Post: Larz60+
  Transfer Toplevel window entry to root window entry with TKinter HBH 0 675 Jan-23-2020, 09:00 PM
Last Post: HBH
  Issue on tkinter with buttons Reldaing 1 600 Jan-07-2020, 08:21 AM
Last Post: berckut72
  [Tkinter] Mouse click event not working on multiple tkinter window evrydaywannabe 2 301 Dec-16-2019, 04:47 AM
Last Post: woooee
  [Tkinter] Window geometry appears different on Win and Linux steve_shambles 6 288 Nov-29-2019, 12:30 AM
Last Post: steve_shambles
  tkinter window and turtle window error 1885 3 447 Nov-02-2019, 12:18 PM
Last Post: 1885
  [Tkinter] Extrakt a Variable from a closed tkinter window hWp 5 469 Aug-23-2019, 09:01 PM
Last Post: woooee
  [Tkinter] Tkinter window pop up again when i click button Orimura_Sandy 1 813 May-12-2019, 08:17 PM
Last Post: joe_momma
  [Tkinter] Top Level Window - from tkinter import * francisco_neves2020 6 691 Apr-23-2019, 09:27 PM
Last Post: francisco_neves2020
  tkinter- adding a new window after clicking a button built on the gui ShashankDS 2 1,806 Apr-18-2019, 12:48 PM
Last Post: ShashankDS

Forum Jump:


Users browsing this thread: 1 Guest(s)