0
0 комментариев

Есть у меня код авторизации написанный на Python3. Но он при запуске отоброжается в отдельном окне, а нужно чтоб он отоброжался и запускался в терминале Ubuntu. Вроде задача лёгкая, но у меня чет не выходит. Надеюсь на Вашу помощь.

<code><span class="com"># -*- coding: utf-8 -*-</span>
<span class="kwd">from</span></code><span class="pln"> tkinter </span><code><span class="kwd">import</span> <span class="pun">*</span>
<span class="kwd">import</span><span class="pln"> os

</span><span class="kwd">def</span><span class="pln"> login_verify</span><span class="pun">():</span><span class="pln">
    username1 </span><span class="pun">=</span><span class="pln"> username_verify</span><span class="pun">.</span><span class="pln">get</span><span class="pun">()</span><span class="pln">
    password1 </span><span class="pun">=</span><span class="pln"> password_verify</span><span class="pun">.</span><span class="pln">get</span><span class="pun">()</span><span class="pln">
    list_of_dir </span><span class="pun">=</span><span class="pln"> os</span><span class="pun">.</span><span class="pln">listdir</span><span class="pun">()</span>
    <span class="kwd">if</span><span class="pln"> username1 </span><span class="kwd">in</span><span class="pln"> list_of_dir</span><span class="pun">:</span><span class="pln">
        file </span><span class="pun">=</span><span class="pln"> open </span><span class="pun">(</span><span class="pln">username1</span><span class="pun">,</span><span class="str">"r"</span><span class="pun">)</span><span class="pln">
        verify </span><span class="pun">=</span><span class="pln"> file</span><span class="pun">.</span><span class="pln">read</span><span class="pun">().</span><span class="pln">splitlines</span><span class="pun">()</span>
        <span class="kwd">if</span><span class="pln"> password1 </span><span class="kwd">in</span><span class="pln"> verify</span><span class="pun">:</span>
            <span class="kwd">print</span> <span class="pun">(</span><span class="str">"Удачная авторизация"</span><span class="pun">)</span>
        <span class="kwd">else</span><span class="pun">:</span>
            <span class="kwd">print</span> <span class="pun">(</span><span class="str">"Имя пользователя не найденно / неверный пароль"</span><span class="pun">)</span>

    <span class="kwd">else</span> <span class="pun">:</span>
        <span class="kwd">print</span> <span class="pun">(</span><span class="str">"Имя пользователя не найденно / неверный пароль"</span><span class="pun">)</span>

<span class="kwd">def</span><span class="pln"> login</span><span class="pun">():</span>
    <span class="kwd">global</span><span class="pln"> screnn2
    </span><span class="kwd">global</span><span class="pln"> username_verify
    </span><span class="kwd">global</span><span class="pln"> password_verify
    username_verify </span><span class="pun">=</span> <span class="typ">StringVar</span><span class="pun">()</span><span class="pln">
    password_verify </span><span class="pun">=</span> <span class="typ">StringVar</span><span class="pun">()</span><span class="pln">

    screen2 </span><span class="pun">=</span> <span class="typ">Toplevel</span><span class="pun">(</span><span class="pln">screen</span><span class="pun">)</span><span class="pln">
    screen2</span><span class="pun">.</span><span class="pln">geometry</span><span class="pun">(</span><span class="str">"500x300"</span><span class="pun">)</span><span class="pln">
    screen2</span><span class="pun">.</span><span class="pln">title</span><span class="pun">(</span><span class="str">"login"</span><span class="pun">)</span>
    <span class="typ">Label</span><span class="pun">(</span><span class="pln">screen2</span><span class="pun">,</span><span class="pln">text</span><span class="pun">=</span><span class="str">"Please enter the information for login "</span><span class="pun">,</span><span class="pln">height</span><span class="pun">=</span> <span class="str">'2'</span><span class="pun">,</span><span class="pln">width</span><span class="pun">=</span><span class="str">'30'</span><span class="pun">).</span><span class="pln">pack</span><span class="pun">()</span>
    <span class="typ">Label</span><span class="pun">(</span><span class="pln">screen2</span><span class="pun">,</span><span class="pln">text</span><span class="pun">=</span><span class="str">""</span><span class="pun">,</span><span class="pln">height</span><span class="pun">=</span> <span class="str">'2'</span><span class="pun">,</span><span class="pln">width</span><span class="pun">=</span><span class="str">'30'</span><span class="pun">).</span><span class="pln">pack</span><span class="pun">()</span>
    <span class="typ">Label</span><span class="pun">(</span><span class="pln">screen2</span><span class="pun">,</span><span class="pln">text</span><span class="pun">=</span><span class="str">"логин : "</span><span class="pun">,</span><span class="pln">height</span><span class="pun">=</span> <span class="str">'2'</span><span class="pun">,</span><span class="pln">width</span><span class="pun">=</span><span class="str">'30'</span><span class="pun">).</span><span class="pln">pack</span><span class="pun">()</span><span class="pln">
    username_entry1 </span><span class="pun">=</span> <span class="typ">Entry</span><span class="pun">(</span><span class="pln">screen2</span><span class="pun">,</span><span class="pln">textvariable </span><span class="pun">=</span><span class="pln"> username_verify</span><span class="pun">)</span><span class="pln">
    username_entry1</span><span class="pun">.</span><span class="pln">pack</span><span class="pun">()</span>
    <span class="typ">Label</span><span class="pun">(</span><span class="pln">screen2</span><span class="pun">,</span><span class="pln">text</span><span class="pun">=</span><span class="str">""</span><span class="pun">,</span><span class="pln">height</span><span class="pun">=</span> <span class="str">'2'</span><span class="pun">,</span><span class="pln">width</span><span class="pun">=</span><span class="str">'30'</span><span class="pun">).</span><span class="pln">pack</span><span class="pun">()</span><span class="pln">
    password_entry1 </span><span class="pun">=</span> <span class="typ">Entry</span> <span class="pun">(</span><span class="pln">screen2</span><span class="pun">,</span><span class="pln">textvariable </span><span class="pun">=</span><span class="pln"> password_verify</span><span class="pun">)</span><span class="pln">
    password_entry1</span><span class="pun">.</span><span class="pln">pack</span><span class="pun">()</span>
    <span class="typ">Label</span><span class="pun">(</span><span class="pln">screen2</span><span class="pun">,</span><span class="pln">text</span><span class="pun">=</span><span class="str">""</span><span class="pun">,</span><span class="pln">height</span><span class="pun">=</span> <span class="str">'2'</span><span class="pun">,</span><span class="pln">width</span><span class="pun">=</span><span class="str">'30'</span><span class="pun">).</span><span class="pln">pack</span><span class="pun">()</span>
    <span class="typ">Button</span><span class="pun">(</span><span class="pln">screen2</span><span class="pun">,</span><span class="pln"> text</span><span class="pun">=</span><span class="str">"Войти"</span><span class="pun">,</span><span class="pln"> height</span><span class="pun">=</span> <span class="str">"2"</span><span class="pun">,</span><span class="pln">width</span><span class="pun">=</span><span class="str">"30"</span><span class="pun">,</span><span class="pln"> command </span><span class="pun">=</span><span class="pln"> login_verify</span><span class="pun">).</span><span class="pln">pack</span><span class="pun">()</span>

<span class="kwd">def</span><span class="pln"> main_screen</span><span class="pun">():</span>
    <span class="kwd">global</span><span class="pln"> screen
    screen </span><span class="pun">=</span> <span class="typ">Tk</span><span class="pun">()</span><span class="pln">
    screen</span><span class="pun">.</span><span class="pln">geometry</span><span class="pun">(</span><span class="str">"300x250"</span><span class="pun">)</span>
    <span class="typ">Label</span><span class="pun">(</span><span class="pln">text</span><span class="pun">=</span><span class="str">"Авторизация в AquaSpam"</span><span class="pun">).</span><span class="pln">pack</span><span class="pun">()</span>
    <span class="typ">Label</span><span class="pun">(</span><span class="pln">text</span><span class="pun">=</span><span class="str">""</span><span class="pun">,</span><span class="pln">height</span><span class="pun">=</span> <span class="str">'2'</span><span class="pun">,</span><span class="pln">width</span><span class="pun">=</span><span class="str">'30'</span><span class="pun">)</span>
    <span class="typ">Button</span><span class="pun">(</span><span class="pln">text</span><span class="pun">=</span><span class="str">"Войти"</span><span class="pun">,</span><span class="pln">height</span><span class="pun">=</span> <span class="str">'2'</span><span class="pun">,</span><span class="pln">width</span><span class="pun">=</span><span class="str">'30'</span><span class="pun">,</span><span class="pln">bg</span><span class="pun">=</span><span class="str">"blue"</span><span class="pun">,</span><span class="pln">command </span><span class="pun">=</span><span class="pln"> login</span><span class="pun">).</span><span class="pln">pack</span><span class="pun">()</span>
    <span class="typ">Label</span><span class="pun">(</span><span class="pln">text</span><span class="pun">=</span><span class="str">""</span><span class="pun">,</span><span class="pln">height</span><span class="pun">=</span> <span class="str">'2'</span><span class="pun">,</span><span class="pln">width</span><span class="pun">=</span><span class="str">'30'</span><span class="pun">).</span><span class="pln">pack</span><span class="pun">()</span><span class="pln">
    screen</span><span class="pun">.</span><span class="pln">mainloop</span><span class="pun">()</span><span class="pln">

main_screen</span><span class="pun">()</span>

<span class="com">#</span></code><span class="com"> screen.mainloop()</span>

Добавить комментарий