使用侧面菜单栏中的python中的tkinter在多个帧之间切换

时间:2017-08-30 19:05:26

标签: python user-interface tkinter

我正在尝试创建一个侧面菜单栏并使用多个标签作为单击按钮。但是当我执行程序时,只点击一个标签,并在mainarea中显示事件。其他事件不起作用。

请为我提供有用的解决方案。这是我写的代码:

    from Tkinter import *
    import ttk
    root = Tk()
    def MainScreen(self):
      label4 = Label(mainarea,width=100,height=80,text="Prapti Computer 
      Solutions")
      label4.pack(expand=True,fill='both')

   def ClientData(self):
      label4 = Label(mainarea,width=100,height=80,text="Yo this is client data")
      label4.pack(expand=True,fill='both')

   def Report(self):
      label6 = Label(mainarea,width=100,height=80,text="Report is onnnnn!")
      label6.pack(expand=True,fill='both')

   # sidebar
   sidebar = Frame(root, width=400, bg='white', height=500,  borderwidth=2)
   sidebar.pack( fill='y', side='left', anchor='nw')

   #submenus
   label1 = Label( sidebar,width=45,height = 2 , text="HOME", relief=FLAT )
   label1.bind("<Button-1>",MainScreen)
   label1.grid(row=0)

   ttk.Separator(sidebar,orient=HORIZONTAL).grid(row=1, columnspan=5)

   label2 = Label( sidebar,width=45,height = 2 , text="CLIENT", relief=FLAT )
   label2.bind("<Button-1>",ClientData)
   label2.grid(row=2)

   ttk.Separator(sidebar,orient=HORIZONTAL).grid(row=3, columnspan=5)

   label3 = Label( sidebar,width=45,height = 2 , text="REPORT", relief=FLAT )
   label3.bind("<Button-1>",Report)
   label3.grid(row=4)

   # main content area
   mainarea = Frame(root, bg='#CCC', width=500, height=500)
   mainarea.pack(expand=True, fill='both', side='right')
   root.attributes('-alpha', 0.98)

   root.mainloop()

谢谢。

1 个答案:

答案 0 :(得分:0)

You keep packing things but you never remove them. You need to remove the current page before switching to the new page.

For example:

import java.util.LinkedList;
import java.util.List;

public class BestSequence {

public static List<String> match(String word, List<String> subsequences) {
    int n = word.length();

    //let s(0) :=  {}
    List<List<String>> s = new LinkedList<>();
    for(int i = 0; i <= n; i++)
        s.add(new LinkedList<>());

    //for i from 1 to n
    for(int i = 1; i <= n; i++) {
        //let minSize := +inf.
        int minSize = Integer.MAX_VALUE;

        //for all sequences mx from m1 to m9
        for(String mx : subsequences) {
            //let j := i - mx.length
            int j = i - mx.length();

            if(j < 0)
                continue;

            //if s(j) + mx = the first i char of word
            if(word.substring(0, i).equals(concat(s.get(j)) + mx)) {
                //if size of s(j) + mx is less than minSize
                if(s.get(j).size() + 1 < minSize) {
                    //minSize := size of s(j) + mx
                    minSize = s.get(j).size() + 1;
                    //s(i) := s(j) + mx
                    List<String> sj = new LinkedList<>(s.get(j));
                    sj.add(mx);
                    s.set(i, sj);
                }
            }
        }
    }
    return s.get(n);
}

private static String concat(List<String> strs) {
    String s = "";
    for(String str : strs) {
        s += str;
    }
    return s;
}

}
相关问题