PythonTkinter弹出窗口在Macos上不起作用

2024-04-26 03:37:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图打开一个弹出窗口点击。同样的情况不是作为弹出窗口打开,而是在已经打开的窗口中打开另一个选项卡。而且,当我最大化窗口时,单击功能根本不起作用。你知道吗

enter image description here

我的代码如下:

from tkinter import *
from tkinter import ttk
import shelve
import pyperclip
import os

def popupmsg(msg):
    popup = Tk()
    popup.wm_title("!")
    label = ttk.Label(popup, text=msg)
    label.pack(side="top", fill="x", pady=10)
    B1 = ttk.Button(popup, text="Okay", command = popup.destroy)
    B1.pack()
    popup.mainloop()

class Window(Frame):

    def __init__(self, master=None):
        Frame.__init__(self, master)               
        self.master = master
        self.init_window()

    def init_window(self):
        self.master.title("uClip - Your personal clipboard")
        self.pack(fill = BOTH, expand =1)
        global paste_entry
        paste_entry = Entry(self)
        paste_entry.grid(row=1, sticky="e")
        global copy_entry
        copy_entry = Entry(self)
        copy_entry.grid(row=2, sticky="e")
        global delete_entry
        delete_entry = Entry(self)
        delete_entry.grid(row=3, sticky="e")
        button1 = Button(self, text="Paste to uClip", command= lambda:popupmsg("Pop Up")).grid(row=1,column=1)
        button2 = Button(self, text="Copy from uClip", command=None).grid(row=2,column=1)
        button4 = Button(self, text="Delete from uClip",command=None).grid(row=3, column=1)
        button3 = Button(self, text="List all Keywords",command=None).grid(row=4, sticky="e")
        button5 = Button(self, text="Clear uClip",command=None).grid(row=5, sticky="e")
root = Tk()
root.geometry("400x300")
root.resizable(None, None)
uClip = Window(root)

root.mainloop()

Tags: textfromimportselfmasternonebuttonroot