Home > other >  The questions in the Tkinter controls
The questions in the Tkinter controls

Time:09-30

Below all controls are not centered, could you tell me how to modify the code to make them all center configuration?

 import tkinter as tk 


The class ReNamer (tk. Tk) :
Def __init__ (self) :
Super () __init__ ()
The self. The value=https://bbs.csdn.net/topics/0
Label_info=tk. Label (self, text="both Please select a folder:")
Btn_select=tk. The Button (self, text="Click Me", width=8)
Btn_check=tk. The Button (self, text="Check," width=8)
Label_show=tk. Label (self, text={} "the file (s) renamed". The format (self. Value))

# opts={' ipadx: 10, 'ipady: 10,' padx: 10, 'pady: 10,' sticky ':' nswe}
Label_info. The grid (row=0, the column=0, columnspan=2)
Btn_select. The grid (row=1, the column=0)
Btn_check. The grid (row=1, the column=2)
Label_show. The grid (row=2, the column=0, columnspan=2)


If __name__=="__main__" :
Root=ReNamer ()
Root. Mainloop ()

CodePudding user response:

Change the grid to pack?
 
The import tkinter as tk

The class ReNamer (tk. Tk) :
Def __init__ (self) :
Super () __init__ ()
The self. The value=https://bbs.csdn.net/topics/0
Label_info=tk. Label (self, text="both Please select a folder:")
Btn_select=tk. The Button (self, text="Click Me", width=8)
Btn_check=tk. The Button (self, text="Check," width=8)
Label_show=tk. Label (self, text={} "the file (s) renamed". The format (self. Value))

# opts={' ipadx: 10, 'ipady: 10,' padx: 10, 'pady: 10,' sticky ':' nswe}

# label_info. The grid (row=0, the column=0, columnspan=2)
# btn_select. The grid (row=1, the column=0)
# btn_check. The grid (row=1, the column=2)
# label_show. The grid (row=2, the column=0, columnspan=2)
Label_info. Pack ()
Btn_select. Pack ()
Btn_check. Pack ()
Label_show. Pack ()

If __name__=="__main__" :
Root=ReNamer ()
Root. Mainloop ()

CodePudding user response:

reference 1/f, ice wind of reply:
change the grid to pack?
 
The import tkinter as tk

The class ReNamer (tk. Tk) :
Def __init__ (self) :
Super () __init__ ()
The self. The value=https://bbs.csdn.net/topics/0
Label_info=tk. Label (self, text="both Please select a folder:")
Btn_select=tk. The Button (self, text="Click Me", width=8)
Btn_check=tk. The Button (self, text="Check," width=8)
Label_show=tk. Label (self, text={} "the file (s) renamed". The format (self. Value))

# opts={' ipadx: 10, 'ipady: 10,' padx: 10, 'pady: 10,' sticky ':' nswe}

# label_info. The grid (row=0, the column=0, columnspan=2)
# btn_select. The grid (row=1, the column=0)
# btn_check. The grid (row=1, the column=2)
# label_show. The grid (row=2, the column=0, columnspan=2)
Label_info. Pack ()
Btn_select. Pack ()
Btn_check. Pack ()
Label_show. Pack ()

If __name__=="__main__" :
Root=ReNamer ()
Root. Mainloop ()


So, two buttons arranged up and down, I want to look at the button side by side effects, I put the line (row) is set to 3, column (column) is set to 3, it is ok to:
 class ReNamer (tk) tk) : 
Def __init__ (self) :
Super () __init__ ()
The self. The title (" ReNamer V2.0 ")
The self. The value=https://bbs.csdn.net/topics/0
Label_info=tk. Label (self, text="both Please select a folder:")
Btn_select=tk. The Button (self, text="Click Me", width=10)
Btn_check=tk. The Button (self, text="Check," width=10)
Label_show=tk. Label (self, text={} "the file (s) renamed". The format (self. Value))

Label_info. The grid (row=0, the column=1)
Btn_select. The grid (row=1, the column=0, padx=50)
Btn_check. The grid (row=1, the column=2, padx=50)
Label_show. The grid (row=2, the column=1)


If __name__=="__main__" :
Root=ReNamer ()
Root. Mainloop ()

But the spacing between button is too wide, how to narrow the gap?

CodePudding user response:

The two buttons with a Frame in the Frame on the layout
 
The import tkinter as tk

The class ReNamer (tk. Tk) :
Def __init__ (self) :
Super () __init__ ()
The self. The title (" ReNamer V2.0 ")
The self. The value=https://bbs.csdn.net/topics/0
Label_info=tk. Label (self, text="both Please select a folder:")
The panel=tk. Frame (self)
Btn_select=tk. The Button (panel, text="Click Me", width=10)
Btn_check=tk. The Button (panel, text="Check", width=10)
Btn_select. The grid (row=1, the column=0, padx=10)
Btn_check. The grid (row=1, the column=2, padx=10)
Label_show=tk. Label (self, text={} "the file (s) renamed". The format (self. Value))

Label_info. The grid (row=0, the column=1)
A panel. The grid (row=1, the column=1)
Label_show. The grid (row=2, the column=1)

If __name__=="__main__" :
Root=ReNamer ()
Root. Mainloop ()
  • Related