投稿

tkinter 数当てゲーム 改良 トライカウント表示

イメージ
import tkinter as tk from random import randint def get(): global count_number number = guess.get() if number random_number: count_number +=1 count.set(count_number) hint.set("Lower!") root.after(1000, clear_hint) else: hint.set("Well guessed!") count_number +=1 count.set(count_number) root.after(5000, setup) def setup(): global random_number global count_number random_number = randint(1, 100) guess.set(0) count.set(0) hint.set("Start Guessing!") root.after(5000, clear_hint) def clear_hint(): hint.set("") root = tk.Tk() root.geometry("300x60") root.title("数当てゲーム(1-100)") hint = tk.StringVar() guess = tk.IntVar() count=tk.IntVar() random_number = 0 count_number=0 tk.Entry(textvariable=guess).grid(column=0, row=0) tk.Button(root, text="Guess", command=get).grid(column=1, row=0) tk.Label(root, tex...

tkinter 数当てゲーム

イメージ
from random import randint def get(): number = guess.get() if number random_number: hint.set("Lower!") root.after(1000, clear_hint) else: hint.set("Well guessed!") root.after(5000, setup) def setup(): global random_number random_number = randint(1, 100) guess.set(0) hint.set("Start Guessing!") root.after(5000, clear_hint) def clear_hint(): hint.set("") root = tk.Tk() root.geometry("300x200") root.title("数当てゲーム(1-100)") hint = tk.StringVar() guess = tk.IntVar() random_number = 0 tk.Entry(textvariable=guess).grid(column=0, row=0) tk.Button(root, text="Guess", command=get).grid(column=1, row=0) tk.Label(root, textvariable=hint).grid(column=0, row=1) setup()

random.randint

random.randint(a, b)¶ Return a random integer N such that a

C言語と異なる点

① 変数の宣言不要です ② char 型はない。 すべて文字列で表す。 ③ 一つの変数で、異なる型を扱える。 最後に代入した型となる。 ④ OOPである。 ⑤ プログラム構造をインデントで表現する ⑥ 配列はなく、文字列、リスト、タプル などで操作する。 ⑦ コンパイラーではなく、インタープリターである。 ⑧ 高速処理が必須の場合は、関数を用いて書く(関数自体はC言語で作られている。) ⑨ 構造体はクラスで書く ⑩ ポインター はない。 ⑪ 自前関数の定義は参照前に定義する。 ⑫ 参照するモジュールは、プログラムの先頭でimportする

Add image on a Tkinter button

イメージ
 プログラムソース from tkinter import * from tkinter.ttk import * root = Tk() Label(root, text='GeekforGeeks',       font=('Verdana',15)).pack(side=TOP,pady=10) photo = PhotoImage(file=r"c:\python\mydog2020.PNG") photoimage=photo.subsample(3,3) Button(root,text='Click Me !',        image=photoimage,compound=TOP).pack(side=TOP) mainloop() compound=LEFT に変更した場合 Tkinter  is a Python module which is used to create GUI (Graphical User Interface) applications with the help of varieties of widgets and functions. Like any other GUI module it also supports images i.e you can use images in the application to make it more attractive. Image can be added with the help of  PhotoImage()  method. This is a Tkinter method which means you don’t have to import any other module in order to use it. Important:  If both image and text are given on  Button , the text will be dominated and only image will appear on the Button. But if you want to show both...

WEB SITE: mumpy.org/learn

イメージ
mumpy.org/learn

matplotlib.pyplot.plot

matplotlib.pyplot.plot