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

2023-05-16

我是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()

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

python tkinter 按钮 位置_如何使Tkinter按钮置于特定位置? 的相关文章

随机推荐