Python Forum
[Tkinter] Tkinter window issue
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
Reply
#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.
Reply
#3
For starters, alertwindow should be a Toplevel. When there is more than one instance of Tk(), the results are unpredictable.
Reply
#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?
Reply
#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()
           
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 344 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  Tkinter multiple windows in the same window tomro91 1 788 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  Centering and adding a push button to a grid window, TKinter Edward_ 15 4,386 May-25-2023, 07:37 PM
Last Post: deanhystad
Lightbulb [Tkinter] Tkinter Class Import Module Issue AaronCatolico1 6 2,972 Sep-06-2022, 03:37 PM
Last Post: AaronCatolico1
  [Tkinter] Open tkinter colorchooser at toplevel (so I can select/focus on either window) tabreturn 4 1,831 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  [Tkinter] Background inactivity timer when tkinter window is not active DBox 4 2,866 Apr-16-2022, 04:04 PM
Last Post: DBox
  why my list changes to a string as I move to another window in tkinter? pymn 4 2,547 Feb-17-2022, 07:02 AM
Last Post: pymn
  [Tkinter] Tkinter Window Has no Title Bar gw1500se 4 2,795 Nov-07-2021, 05:14 PM
Last Post: gw1500se
  "tkinter.TclError: NULL main window" Rama02 1 5,784 Feb-04-2021, 06:45 PM
Last Post: deanhystad
  Super basic tkinter arduino issue Kurta 3 2,377 Jan-07-2021, 05:22 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020