我的程序有一个库,可以打开一个新窗口
这是库(名为make_entry):
use Hexavel\Console\AppNameCommand;
use Illuminate\Console\Events\ArtisanStarting;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Support\ServiceProvider;
class NameCommandProvider extends ServiceProvider
{
/**
* Register any other events for your application.
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @return void
*/
public function boot(Dispatcher $events)
{
$events->listen(ArtisanStarting::class, function ($event) {
$event->artisan->resolve('command.app.name');
}, -1);
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton('command.app.name', function ($app) {
return new AppNameCommand($app['composer'], $app['files']);
});
}
}
如果我自己运行这个库,那么一切正常,但是当我从另一个程序导入它时,唯一不起作用的是from tkinter import *
def Create():
Window = Tk() # window
Window.geometry("900x500+50+50") # heightxwidth+x+y
mainPanel = Canvas(Window, width = 900, height = 500) # main screen
mainPanel.pack()
anyvar = StringVar() # the text in the entry
entry = Entry(mainPanel, width = 40, font = ("Purisa", 12, "bold"), justify = "center", textvariable = anyvar) # the entry
mainPanel.create_window(200, 100, window = entry)
anyvar.set("This doesnt work!!!!!")
Window.mainloop()
#Create()
。
这是我导入它的地方:(大部分代码被删除)
anyvar.set("This doesnt work!!!!!")
有没有办法解决这个问题而不删除任何窗口?
答案 0 :(得分:3)
你有两个Tk()实例混淆了Tkinter。我猜测StringVar()将转到另一个(第一个)实例。相反,将唯一的实例传递给函数,并使用Toplevel作为新窗口。
from tkinter import *
def Create(root):
window=Toplevel(root)
window.geometry("900x500+50+50") # heightxwidth+x+y
mainpanel = Canvas(window, width = 900, height = 500) # main screen
mainpanel.pack()
anyvar = StringVar() # the text in the entry
entry = Entry(mainpanel, width = 40, font = ("Purisa", 12, "bold"), justify = "center", textvariable = anyvar) # the entry
mainpanel.create_window(200, 100, window = entry)
anyvar.set("This doesnt work!!!!!")
和
from tkinter import *
Window = Tk()
import make_entry
make_entry.Create(Window)
Window.mainloop()