Python Forum
[Tkinter] Tkinter problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Tkinter problem
#1
1.if you just run this, youll have a window to input 'order' and 'Rs'.
2.Enter a number in 'order' and press ok.
3.Change the number in 'order' again and press ok again.
youll know what wrong's with it.

QUESTIONS:

First: how can i cover these elements created by clicking 'ok'?
Second: is there any way that i dont have to have a button but show the elements right after i enter a number in 'order'

Thank you!!!!

import tkinter as tk
R=[]
C=[]
order=0
# GUI
def GUI():
    window=tk.Tk()
    window.title('variable assignment')
    window.geometry('500x600')
    order_label=tk.Label(window,text='order',font=(14))
    order_label.pack()
    order_msgbx=tk.Entry(window,show=None)
    print(type(order))
    order_msgbx.pack()
    R_s_label=tk.Label(window,text='Rs',font=(14))
    R_s_label.pack()
    R_s_msgbx=tk.Entry(window,show=None)
    R_s=R_s_msgbx.get()
    R_s_msgbx.pack()
    R_msgbx=[]
    C_msgbx=[]
    R_label_list=locals()
    C_label_list=locals()

    def RC_button():
        order=int(order_msgbx.get())
        print(order)
        window=tk.Tk()
        if order>0:
            for n in range(order):
                R_label_list['R_label_' + str(n+1)] = tk.Label(window,text='R'+str(n+1),font=(14))
                R_label_list['R_label_' + str(n+1)].pack()
                R_msgbx0=tk.Entry(window,show=None)
                R_msgbx.append(R_msgbx0)
                R_msgbx[n].pack()
                R.append(R_msgbx[n].get)
                C_label_list['C_label_' + str(n+1)] = tk.Label(window,text='C'+str(n+1),font=(14))
                C_label_list['C_label_' + str(n+1)].pack()
                C_msgbx0=tk.Entry(window,show=None)
                C_msgbx.append(C_msgbx0)
                C_msgbx[n].pack()
                C.append(C_msgbx[n].get)
    RC_button=tk.Button(window, text='OK',width=15,height=2,command=RC_button)
    RC_button.pack()
    window.mainloop()
GUI()
Reply
#2
Quote:RC_button=tk.Button(window, text='OK',width=15,height=2,command=RC_button)
this statement calls itself when button pressed.

you need to do some renaming.

calling the function which is named same as button is bad coding, it will recreate widgets each time
and weird things will start at some point.

I strongly suggest taking a good tutorial (at least the parts about buttons)
I'd suggest: https://www.python-course.eu/python_tkinter.php
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python3 tkinter radiobutton problem Nick_tkinter 14 552 Feb-15-2021, 11:01 PM
Last Post: Nick_tkinter
  tkinter python button position problem Nick_tkinter 3 513 Jan-31-2021, 05:15 AM
Last Post: deanhystad
  [Tkinter] ClockIn/Out tkinter problem Maryan 2 399 Oct-12-2020, 03:42 AM
Last Post: joe_momma
  tkinter| listbox.insert problem Maryan 3 447 Sep-29-2020, 05:34 PM
Last Post: Yoriz
  Tkinter problem DPaul 6 912 May-28-2020, 03:40 PM
Last Post: DPaul
  [Tkinter] Tkinter - I have problem after import varaible or function from aGUI to script johnjh 2 695 Apr-17-2020, 08:12 PM
Last Post: johnjh
  [Tkinter] Problem with tkinter when creating .exe file Jan_97 2 1,708 Feb-27-2020, 05:17 PM
Last Post: Jan_97
  Problem with Submit button Tkinter Reldaing 2 988 Jan-05-2020, 01:58 AM
Last Post: balenaucigasa
  tkinter GUI, problem running seperate files fishglue 17 1,913 Oct-15-2019, 02:56 PM
Last Post: Denni
  [python] [Tkinter] Problem bidding combobox with np.array NEL 3 1,099 Aug-04-2019, 11:07 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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