python tkinter 按钮 位置_如何使Tkinter按钮置于特定位置?

这篇博客讨论了Python新手在使用Tkinter创建GUI时遇到的问题。作者尝试将按钮通过place()方法放置在特定位置(x=200, y=100),但按钮消失。问题在于使用place()后不应再使用pack(),因为这两种布局管理器不能同时使用。解决方案是删除self.nxt_form.pack(),只保留place()方法来精确布置按钮。
摘要由CSDN通过智能技术生成

我是python新手,所以我试图制作一个GUI,因为我必须将一个按钮放在一个特定的位置。在

我试着用self.nxt_form.place(x=200,y=100)代替self.nxt_form.pack()。在

但是按钮不见了,只有画面出现了。你能告诉我怎么把按钮放在特定的位置吗?在

代码如下:import tkinter as tk

class Main_form:

def __init__(self, root,title="Simulated MTBF"):

self.root = root

self.frame = tk.Frame(self.root)

"""Button nxt_form which moves to next form"""

self.nxt_form = tk.Button(self.frame, text = 'Next Form', width = 25,command = self.new_window)

self.nxt_form.pack()

self.frame.pack()

"""command to open new window by clicking Button """

def new_window(self):

self.newWindow = tk.Toplevel(self.root)

self.app = Demo2(self.newWindow)

class Demo2:

def __init__(self, root):

self.root = root

self.frame = tk.Frame(self.root)

self.quitButton = tk.Button(self.frame, text = 'Quit', width = 25, command = self.close_windows)

self.quitButton.pack()

self.frame.pack()

def close_windows(self):

self.root.destroy()

def main():

root = tk.Tk()

app = Main_form(root)

root.mainloop()

if __name__ == '__main__':

main()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值