Tkinter模块-任务栏未显示

时间:2018-10-19 22:23:57

标签: python python-3.x tkinter

有人知道为什么它不会在我的代码中显示任务栏。我试图让顶部说退出和文件下拉菜单中的信息。我是tkinter的新手,请只需要一点帮助。另外,如果您有任何改进建议,我将不胜感激!

我的代码如下:

from time import sleep
from tkinter import * 
from tkinter import messagebox, ttk, Tk

root = Tk()

class GUI():

    def taskbar(self):

        menu = Menu(root)
        file = Menu(menu)
        file.add_command(label="Exit", command=self.exit_GUI)
        file.add_command(label = "Information", command=self.info_popup)        

   def Main_Menu(self):

        topFrame = Frame(root)
        topFrame.pack()
        bottomFrame = Frame(root)
        bottomFrame.pack(side=BOTTOM)

        Income_button = Button(topFrame, text="Enter your incomes", command=self.Income)
        Expense_button = Button(topFrame, text="Enter your expenses", command=self.Expense)
        Total_button = Button(bottomFrame, text="View Results", command=self.Total)
        Income_button.pack()
        Expense_button.pack()
        Total_button.pack()

    def Income(self):
        pass

    def Expense(self):
        pass

    def Total(self):
        pass

    def exit_GUI(self):
        exit()

    def info_popup(self):
        pass

g = GUI()
g.taskbar()
g.Main_Menu()
g.Income()
g.Expense()
g.Total()
g.info_popup()

root.mainloop()

1 个答案:

答案 0 :(得分:2)

您需要将import java.awt.Color; import java.awt.Dimension; import javax.swing.JComboBox; import javax.swing.JPanel; @SuppressWarnings("serial") public class thing2 extends JPanel { /** * Declaring all variables and components to be used within the GUI */ private String[] list = { "Inches/Centimeters", "Miles/Kilometres", "Pounds/Kilograms", "Gallons/Litres", "Feet/Metres", "Celcius/Kelvin", "Acres/Hectare" }; thing2() { JComboBox<String> conversionCombo = new JComboBox<String>(list); // creating JComboBox add(conversionCombo); setPreferredSize(new Dimension(800, 80)); setBackground(Color.WHITE); } } 函数更改为:

taskbar

这将告诉窗口使用菜单栏。