小编Che*_*iao的帖子

如何使用Python tkinter创建子窗口?

我正在使用Python 3.3和tkinter为行人逃离模拟制作GUI界面.

我写了两个模拟程序,但效果很好.但是,当我试图从我的主应用程序中调用它时,我遇到了困难.我希望模拟窗口出现在一个单独的窗口中(创建主窗口的子窗口).

#flee_GUI.py
#!/usr/bin/env python
import tkinter

class MenuBar(tkinter.Menu):
    def __init__(self,parent):
        tkinter.Menu.__init__(self,parent)
        ###File###
        fileMenu = tkinter.Menu(self, tearoff=False)
        self.add_cascade(label="File",underline=0, menu=fileMenu)
        fileMenu.add_command(label='Open',underline=1)
        fileMenu.add_separator()
        fileMenu.add_command(label="Exit", underline=1, command=self.quit)
        ###Run###
        runMenu=tkinter.Menu(self,tearoff=False)
        self.add_cascade(label='Run',underline=1,menu=runMenu)
        runMenu.add_command(label='Open Bounary Model',underline=1,command=runModel1)


class Frame(tkinter.Tk):
    def __init__(self,parent):
        tkinter.Frame.__init__(self,parent)
        self.parent=parent

def runModel1():
    from drawcanvas_Alpha_7_0_open_border import cell
    I=cell(None)

class App(tkinter.Tk):
    def __init__(self,parent):
        tkinter.Tk.__init__(self,parent)
        self.parent=parent
        runModel1()

        menubar=MenuBar(self)
        self.config(menu=menubar)

if __name__=='__main__':
    app=App(None)
    app.mainloop()

#drawcanvas_Alpha_7_0_open_border.py
#!/usr/bin/env python
# -*- coding:utf-8 -*-

#Run this by python3.x.
#If you are using Python2.x,be aware of the difference such as print,Tkinter …
Run Code Online (Sandbox Code Playgroud)

python window tkinter

11
推荐指数
1
解决办法
8万
查看次数

WPF和MVVM:从文本框中获取值并将其发送到ViewModel

当我按下按钮时,我正试图获得两个Texbox的值(我正在模拟一个登录窗口).按钮中指定的命令正确触发,但我不知道如何获取文本框的值来执行"登录".

这是我的ViewModel:

class LoginViewModel : BaseViewModel
{   
    public LoginViewModel()
    {

    }

    private DelegateCommand loginCommand;
    public ICommand LoginCommand
    {
        get
        {
            if (loginCommand == null)
                loginCommand = new DelegateCommand(new Action(LoginExecuted),
                               new Func<bool>(LoginCanExecute));
                return loginCommand;
            }
        } 

    public bool LoginCanExecute()
    {
        //Basic strings validation...
        return true;
    }
    public void LoginExecuted()
    {
        //Do the validation with the Database.
        System.Windows.MessageBox.Show("OK");
    } 
}
Run Code Online (Sandbox Code Playgroud)

这是观点:

 <Grid DataContext="{StaticResource LoginViewModel}">

            <TextBox x:Name="LoginTxtBox" HorizontalAlignment="Left" Height="23" Margin="34,62,0,0" Width="154" />
            <PasswordBox x:Name="PasswordTxtBox" HorizontalAlignment="Left" Height="23" Margin="34,104,0,0" Width="154"/>
            <Button x:Name="btnAccept"
            HorizontalAlignment="Left" 
            Margin="34,153,0,0" 
            Width="108" …
Run Code Online (Sandbox Code Playgroud)

wpf mvvm delegatecommand icommand

7
推荐指数
1
解决办法
3万
查看次数

标签 统计

delegatecommand ×1

icommand ×1

mvvm ×1

python ×1

tkinter ×1

window ×1

wpf ×1