当前位置: 首页 > news >正文

做明星ps黄图网站/湖南长沙最新疫情

做明星ps黄图网站,湖南长沙最新疫情,上海工业网站建设,新公司网站建设方案我使用Tkinter创建了一个带有不同菜单选项的GUI(下面是一个类似的例子).每个菜单都有不同的命令,单击这些命令时会创建一个新框架.现在发生的事情是,如果我切换到另一个命令,新帧将堆叠在当前帧之下而不是替换旧帧.我想知道前进的最佳方式是什么.import Tkinter as tkinterroot…

我使用Tkinter创建了一个带有不同菜单选项的GUI(下面是一个类似的例子).每个菜单都有不同的命令,单击这些命令时会创建一个新框架.现在发生的事情是,如果我切换到另一个命令,新帧将堆叠在当前帧之下而不是替换旧帧.

我想知道前进的最佳方式是什么.

import Tkinter as tkinter

root = tkinter.Tk()

root.minsize(400,300)

welcome = tkinter.Frame(root).grid()

label = tkinter.Label(welcome, text="Welcome to my program").grid(row=0, column=3)

button = tkinter.Button(welcome,text="Exit",command=root.destroy).grid(row=3, column=1)

def newFrame():

newFrame = tkinter.Frame(root).grid()

newFrame_name = tkinter.Label(newFrame, text="This is another frame").grid()

menu = tkinter.Menu(root)

root.config(menu=menu)

main_menu = tkinter.Menu(menu)

menu.add_cascade(label="Main Menu", menu= main_menu)

main_menu.add_command(label="New Frame", command=newFrame)

main_menu.add_command(label="Another Frame", command=newFrame)

#menu.add_command(label="Exit", command=root.destroy, menu= filemenu)

root.mainloop()

现在,如果我在New Frame和Another Frame之间切换,窗口会叠加,但我想要一个窗口替换另一个窗口.

有任何想法吗?谢谢.

最佳答案

这是我最近使用的一种方法的最小例子;关键是在PythonGUI.show_frame中,它将适当的帧移动到前面以供显示.

import Tkinter as tk

class BaseFrame(tk.Frame):

"""An abstract base class for the frames that sit inside PythonGUI.

Args:

master (tk.Frame): The parent widget.

controller (PythonGUI): The controlling Tk object.

Attributes:

controller (PythonGUI): The controlling Tk object.

"""

def __init__(self, master, controller):

tk.Frame.__init__(self, master)

self.controller = controller

self.grid()

self.create_widgets()

def create_widgets(self):

"""Create the widgets for the frame."""

raise NotImplementedError

class ExecuteFrame(BaseFrame):

"""The application home page.

Attributes:

new_button (tk.Button): The button to switch to HomeFrame.

"""

def create_widgets(self):

"""Create the base widgets for the frame."""

self.new_button = tk.Button(self,

anchor=tk.W,

command=lambda: self.controller.show_frame(HomeFrame),

padx=5,

pady=5,

text="Home")

self.new_button.grid(padx=5, pady=5, sticky=tk.W+tk.E)

class HomeFrame(BaseFrame):

"""The application home page.

Attributes:

new_button (tk.Button): The button to switch to ExecuteFrame.

"""

def create_widgets(self):

"""Create the base widgets for the frame."""

self.new_button = tk.Button(self,

anchor=tk.W,

command=lambda: self.controller.show_frame(ExecuteFrame),

padx=5,

pady=5,

text="Execute")

self.new_button.grid(padx=5, pady=5, sticky=tk.W+tk.E)

class PythonGUI(tk.Tk):

"""The main window of the GUI.

Attributes:

container (tk.Frame): The frame container for the sub-frames.

frames (dict of tk.Frame): The available sub-frames.

"""

def __init__(self):

tk.Tk.__init__(self)

self.title("Python GUI")

self.create_widgets()

self.resizable(0, 0)

def create_widgets(self):

"""Create the widgets for the frame."""

# Frame Container

self.container = tk.Frame(self)

self.container.grid(row=0, column=0, sticky=tk.W+tk.E)

# Frames

self.frames = {}

for f in (HomeFrame, ExecuteFrame): # defined subclasses of BaseFrame

frame = f(self.container, self)

frame.grid(row=2, column=2, sticky=tk.NW+tk.SE)

self.frames[f] = frame

self.show_frame(HomeFrame)

def show_frame(self, cls):

"""Show the specified frame.

Args:

cls (tk.Frame): The class of the frame to show.

"""

self.frames[cls].tkraise()

if __name__ == "__main__":

app = PythonGUI()

app.mainloop()

exit()

http://www.lbrq.cn/news/946693.html

相关文章:

  • 做金融看哪些网站有哪些/智慧教育
  • 乔拓云智能建站免费注册/2018十大网络营销案例
  • 在家里组一个服务器做网站/企业网站的优化建议
  • wordpress插入html/seo推广计划
  • 和小学生做的黄色网站/哪个合肥seo好
  • 成立网站要营业执照吗/营销推广方式有哪些
  • 福州网站设计公司/青岛模板建站
  • 外贸网站建设报价差别那么大花钱多吃亏/东莞seo网站排名优化
  • 深圳政府网站建设 论文/以营销推广为主题的方案
  • 苏州创建公司/手机管家一键优化
  • 伍佰亿网站系统/北京网络营销推广外包
  • 网站建设+人员+年终总结/广州seo优化排名推广
  • 动易企业网站/会计培训班一般收费多少
  • 网站建设在哪里备案/太原企业网站建设
  • 中英文企业网站制作/百度关键词分析
  • 医药企业网站建设要哪些备案/兰州网络推广与营销
  • 如何开发动态网站/seo是什么职位
  • 北京网站制作业务如何开展/bt搜索引擎
  • 做网站视频的赚钱吗/app代理推广平台
  • 做背景视频哪个网站好/营销技巧和话术
  • 网站建设企业宣传册/浙江网站推广公司
  • 学而思的网站哪里做的/seo关键词优化公司
  • 平台类网站建设方案/关键词搜索引擎优化推广
  • 门户网站后台管理模板/建立个人网站
  • 关于做暧暧的网站/汕头网站关键词推广
  • 中山火炬开发区建设局网站/安卓优化大师下载
  • 四川建设网站/百度推广的定义
  • 做网站文字编辑工作好不好/如何优化企业网站
  • 阿里云建立网站备案/唯尚广告联盟app下载
  • 政府网站建设绩效评估指标/收录平台
  • CentOS8 使用 Docker 搭建 Jellyfin 家庭影音服务器
  • win11 使用adb 获取安卓系统日志
  • 嵌入式软件--stm32 DAY 9 定时器
  • 循环神经网络--LSTM模型
  • List和Map的区别
  • 交叉编译opencv(Cpp)于arm64架构开发板上