I want to write a code so that every time I press the button, a different flag is drawn. But now, when a flag is drawn by pressing a random button, even if I press it again, only the national flag of that country is drawn. That part is def button27_pressed():. And 랜덤 means random. How can I change the code to draw randomly flag every time I press the button?
from tkinter import *
from turtle import*
from Random import FlagPrint
import random
from 그리스 import Greece
from 대한민국 import Korea
from 덴마크 import Denmark
from 독일 import Germany
from 라트비아 import Latvia
from 룩셈부르크 import Luxembourg
from 리투아니아 import Lithuania
from 말리 import Mali
from 미국 import USA
from 바하마 import Bahamas
from 방글라데시 import Bangladesh
from 벨기에 import Belgium
from 스위스 import Switzerland
from 아이슬란드 import Iceland
from 아일랜드 import Ireland
from 영국 import UK
from 오스트리아 import Austria
from 이탈리아 import Italy
from 인도 import India
from 일본 import Japan
from 중국 import China
from 체코 import Czeh
from 태국 import Thailand
from 튀니지 import Tunisia
from 프랑스 import France
from 헝가리 import Hungary
window=Tk()
window.title("거북이를 이용한 국기 그리기")
window.geometry("540x320")
def button1_pressed():
Greece()
def button2_pressed():
Korea()
def button3_pressed():
Denmark()
def button4_pressed():
Germany()
def button5_pressed():
Latvia()
def button6_pressed():
Luxembourg()
def button7_pressed():
Lithuania()
def button8_pressed():
Mali()
def button9_pressed():
USA()
def button10_pressed():
Bahamas()
def button11_pressed():
Bangladesh()
def button12_pressed():
Belgium()
def button13_pressed():
Switzerland()
def button14_pressed():
Iceland()
def button15_pressed():
Ireland()
def button16_pressed():
UK()
def button17_pressed():
Austria()
def button18_pressed():
Italy()
def button19_pressed():
India()
def button20_pressed():
Japan()
def button21_pressed():
China()
def button22_pressed():
Czeh()
def button23_pressed():
Thailand()
def button24_pressed():
Tunisia()
def button25_pressed():
France()
def button26_pressed():
Hungary()
def button27_pressed():
Country=['그리스','대한민국','덴마크','독일','라트비아','룩셈부르크',
'리투아니아','말리','미국','바하마','방글라데시','벨기에',
'스위스','아이슬란드','아일랜드','영국','오스트리아','이탈리아',
'인도','일본','중국','체코','태국','튀니지','프랑스','헝가리']
Flag=random.choice(Country)
FlagPrint()
def button28_pressed():
Greece()
Korea()
Denmark()
Germany()
Latvia()
Luxembourg()
Lithuania()
Mali()
USA()
Bahamas()
Bangladesh()
Belgium()
Switzerland()
Iceland()
Ireland()
UK()
Austria()
Italy()
India()
Japan()
China()
Czeh()
Thailand()
Tunisia()
France()
Hungary()
def button29_pressed():
bye()
label = Label(window, text="국가를 선택하시오", font=('고딕',20), height=2)
label.grid(row=0,columnspan=6)
button1 = Button(window, text="그리스", width=10, height=2, command=button1_pressed)
button1.grid(row=1,column=0)
button2 = Button(window, text="대한민국", width=10, height=2, command=button2_pressed)
button2.grid(row=1,column=1)
button3 = Button(window, text="덴마크", width=10, height=2, command=button3_pressed)
button3.grid(row=1,column=2)
button4 = Button(window, text="독일", width=10, height=2, command=button4_pressed)
button4.grid(row=1,column=3)
button5 = Button(window, text="라트비아", width=10, height=2, command=button5_pressed)
button5.grid(row=1,column=4)
button6 = Button(window, text="룩셈부르크", width=10, height=2, command=button6_pressed)
button6.grid(row=1,column=5)
button7 = Button(window, text="리투아니아", width=10, height=2, command=button7_pressed)
button7.grid(row=2,column=0)
button8 = Button(window, text="말리", width=10, height=2, command=button8_pressed)
button8.grid(row=2,column=1)
button9 = Button(window, text="미국", width=10, height=2, command=button9_pressed)
button9.grid(row=2,column=2)
button10 = Button(window, text="바하마", width=10, height=2, command=button10_pressed)
button10.grid(row=2,column=3)
button11 = Button(window, text="방글라데시", width=10, height=2, command=button11_pressed)
button11.grid(row=2,column=4)
button12 = Button(window, text="벨기에", width=10, height=2, command=button12_pressed)
button12.grid(row=2,column=5)
button13 = Button(window, text="스위스", width=10, height=2, command=button13_pressed)
button13.grid(row=3,column=0)
button14 = Button(window, text="아이슬란드", width=10, height=2, command=button14_pressed)
button14.grid(row=3,column=1)
button15 = Button(window, text="아일랜드", width=10, height=2, command=button15_pressed)
button15.grid(row=3,column=2)
button16 = Button(window, text="영국", width=10, height=2, command=button16_pressed)
button16.grid(row=3,column=3)
button17 = Button(window, text="오스트리아", width=10, height=2, command=button17_pressed)
button17.grid(row=3,column=4)
button18 = Button(window, text="이탈리아", width=10, height=2, command=button18_pressed)
button18.grid(row=3,column=5)
button19 = Button(window, text="인도", width=10, height=2, command=button19_pressed)
button19.grid(row=4,column=0)
button20 = Button(window, text="일본", width=10, height=2, command=button20_pressed)
button20.grid(row=4,column=1)
button21 = Button(window, text="중국", width=10, height=2, command=button21_pressed)
button21.grid(row=4,column=2)
button22 = Button(window, text="체코", width=10, height=2, command=button22_pressed)
button22.grid(row=4,column=3)
button23 = Button(window, text="태국", width=10, height=2, command=button23_pressed)
button23.grid(row=4,column=4)
button24 = Button(window, text="튀니지", width=10, height=2, command=button24_pressed)
button24.grid(row=4,column=5)
button25 = Button(window, text="프랑스", width=10, height=2, command=button25_pressed)
button25.grid(row=5,column=0)
button26 = Button(window, text="헝가리", width=10, height=2, command=button26_pressed)
button26.grid(row=5,column=1)
button27 = Button(window, text="랜덤", width=10, height=2, command=button27_pressed)
button27.grid(row=5,column=2)
button28 = Button(window, text="All", width=10, height=2, command=button28_pressed)
button28.grid(row=5,column=3)
button29 = Button(window, text="종료", width=10, height=2, command=button29_pressed)
button29.grid(row=5,column=4)
window.mainloop()
This is FlagPrint code.
def FlagPrint():
if(Flag=='그리스'):
Greece()
elif(Flag=='대한민국'):
Korea()
elif(Flag=='덴마크'):
Denmark()
elif(Flag=='독일'):
Germany()
elif(Flag=='라트비아'):
Latvia()
elif(Flag=='룩셈부르크'):
Luxembourg()
elif(Flag=='리투아니아'):
Lithuania()
elif(Flag=='말리'):
Mali()
elif(Flag=='미국'):
USA()
elif(Flag=='바하마'):
Bahamas()
elif(Flag=='방글라데시'):
Bangladesh()
elif(Flag=='벨기에'):
Belgium()
elif(Flag=='스위스'):
Switzerland()
elif(Flag=='아이슬란드'):
Iceland()
elif(Flag=='아일랜드'):
Ireland()
elif(Flag=='영국'):
UK()
elif(Flag=='오스트리아'):
Austria()
elif(Flag=='이탈리아'):
Italy()
elif(Flag=='인도'):
India()
elif(Flag=='일본'):
Japan()
elif(Flag=='중국'):
China()
elif(Flag=='체코'):
Czeh()
elif(Flag=='태국'):
Thailand()
elif(Flag=='튀니지'):
Tunisia()
elif(Flag=='프랑스'):
France()
elif(Flag=='헝가리'):
Hungary()
Aucun commentaire:
Enregistrer un commentaire