multiframe_working.py
import tkinter as tk
from tkinter import *
import POS.secondWindow as sW
class MainWindow(tk.Tk):
def __init__(self):
super().__init__()
# self.title("Main Window")
# self.geometry("600x400+30+30")
# create all of the main containers
top_frame = Frame(self, bg='cyan', width=450, height=50, pady=3) #
top_frame1 = Frame(top_frame, bg='green', width=450, height=50, pady=3) #
center = Frame(self, bg='white', width=50, height=40, padx=3, pady=3)
btm_frame = Frame(self, bg='red', width=450, height=45, pady=3)
btm_frame2 = Frame(self, bg='yellow', width=450, height=60, pady=3)
# layout all of the main containers
self.grid_rowconfigure(1, weight=1)
self.grid_columnconfigure(0, weight=1)
# grid incremented by one added center.title.grid
top_frame.grid(row=0,sticky="nsew")
top_frame1.grid(row=0,sticky="nsew" )
top_frame1.rowconfigure(0,weight=1)
configured to center the text
top_frame1.columnconfigure(0,weight=1)
top_frame.rowconfigure(0,weight=1)
top_frame.columnconfigure(0,weight=1)
center.grid(row=1, sticky="nsew")
btm_frame.grid(row=3, sticky="nsew")
btm_frame2.grid(row=4, sticky="ew")
# create the center widgets
center.grid_rowconfigure(0, weight=1)
center.grid_columnconfigure(1, weight=1)
ctr_left = Frame(center, bg='light gray', width=10, height=190)
ctr_mid = Frame(center, bg='pink', width=250, height=190)
ctr_right = Frame(center, bg='blue', width=200, height=45)
ctr_right1 = Frame(ctr_right, bg='yellow', width=200, height=45 )
ctr_right2 = Frame(ctr_right, bg='sea green', width=200, height=45)
ctr_right3 = Frame(ctr_right, bg='white', width=200, height=45)
ctr_mid_top1 = Frame(ctr_mid , bg='blue', width=100, height=100, padx=3, pady=3)
ctr_mid_top2 = Frame(ctr_mid , bg='red', width=250, height=50, padx=3, pady=3)
ctr_mid_top3 = Frame(ctr_mid , bg='gray', width=250, height=190, padx=3, pady=3)
ctr_mid_top4 = Frame(ctr_mid , bg='skyblue1', width=250, height=190, padx=3, pady=3)
ctr_left.grid(row=0, column=0, sticky="nsew")
ctr_mid.grid(row=0, column=1, sticky="nsew")
ctr_mid_top1.grid(row=0, column=1, sticky="nsew")
ctr_mid_top2.grid(row=1, column=1, sticky="nsew")
ctr_mid_top3.grid(row=2, column=1, sticky="nsew")
ctr_mid_top4.grid(row=3, column=1, sticky="nsew")
ctr_right.grid(row=0, column=2, sticky="ns")
# ACHIEVED: inside grid frame inserted pack frame
ctr_right1.grid(row=0, column=0, sticky="ew",columnspan=3)
ctr_right2.grid(row=1, column=0, sticky="nsew")
ctr_right3.grid(row=2, column=0, sticky="nsew")
if __name__ == '__main__':
window = MainWindow()
window.mainloop()
sample_codes.py
import tkinter as tk
from tkinter import *
from POS.multiframe_working import MainWindow
class import_frame(MainWindow):
def showbutton():
Mybutton= Button(ctrright3,Text="need help")
Mybutton.grid(row=0,column=0)
Mybutton.grid()
if __name__ == '__main__':
import_frame.showbutton
window = MainWindow()
window.mainloop()
**Now how can set a button in ctr_righ3 frame for example.**
我花了将近10天,但无法解决此问题。我有一个GUI框架类,其中定义了所有框架。我想将此框架导入其他类并在这些框架上构建小部件/方法。